本文整理汇总了PHP中Restaurant::update_rating方法的典型用法代码示例。如果您正苦于以下问题:PHP Restaurant::update_rating方法的具体用法?PHP Restaurant::update_rating怎么用?PHP Restaurant::update_rating使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Restaurant
的用法示例。
在下文中一共展示了Restaurant::update_rating方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Review
$new_review = new Review();
$restaurant = new Restaurant();
if ($restaurant->find($restaurant_id)) {
$original_rating = $restaurant->get_rating();
$new_rating = $rate;
$all_reviews = Review::get_all_reviews_by_restaurant($restaurant_id);
// var_dump($all_reviews);
if ($all_reviews) {
$overall_rate = 0;
while ($a_review = $all_reviews->fetch_row()) {
$overall_rate += $a_review[4];
}
$new_rating = ($overall_rate + $rate) / ($all_reviews->num_rows + 1);
}
$new_review->create($fields);
$restaurant->update_rating($new_rating);
$success = true;
$message = 'Adding review complete! Your review will be attached to the restaurant page shortly.';
}
} catch (Exception $e) {
$success = false;
$message = $e->getMessage();
}
$return_result = array('success' => $success, 'message' => $message);
echo json_encode($return_result);
// //add review
// $title = $POST['title'];
// $content = $_POST['content'];
// $rating = $_POST['rating'];
// $date = date('Y-m-d');
// $restaurant_id = $POST['restaurant_id'];