本文整理匯總了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'];