本文整理汇总了PHP中Restaurant::get_rating方法的典型用法代码示例。如果您正苦于以下问题:PHP Restaurant::get_rating方法的具体用法?PHP Restaurant::get_rating怎么用?PHP Restaurant::get_rating使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Restaurant
的用法示例。
在下文中一共展示了Restaurant::get_rating方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: header
if (empty($_POST)) {
header('Location: index.php');
} else {
require_once '../lib/Review.class.php';
require_once '../lib/User.class.php';
require_once '../lib/Restaurant.class.php';
$user_id = $_POST['user_id'];
$restaurant_id = $_POST['restaurant_id'];
$rate = $_POST['rating'];
$content = $_POST['content'];
$fields = array('user_id' => $user_id, 'restaurant_id' => $restaurant_id, 'rating' => $rate, 'content' => $content);
try {
$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.';
}