我有可能误解了这个问题。
我有两个表,用户和评论。 Stars是Reviews表中的一列。
我只是希望能够显示用户的平均星级评分。我无法弄清楚如何访问这些然后找到平均值。
这是我到目前为止所建立的:
// Get Data
$qry = "SELECT * FROM `users` LEFT JOIN `reviews` ON users.userId = reviews.user_id WHERE installation_id = $installation_id";
$res = mysqli_query($mysqli, $qry) or die('-1'.mysqli_error($mysqli));
//$uqry = "SELECT membership FROM users WHERE userId = $uid";
//$current_user = mysqli_query($mysqli, $uqry) or die('-1'.mysqli_error($mysqli));
$getUser = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT membership FROM users WHERE userId = $uid"));
$currentUserLevel = $getUser['membership'];
$user_review_id = 60;
?>
<div class="container">
<div class="content">
<?php if ($msgBox) { echo $msgBox; } ?>
<div class="row">
<?php $lists = array();
while($list = mysqli_fetch_assoc($res)) {
$lists[] = $list;
}
foreach($lists as $list) {
$name = stripslashes($list['usersName']);
$bio = stripslashes($list['usersBio']);
?>
<div class="col-md-4">
<div id = "user-square">
<div class="avatar">
<img src="<?php echo $avatarDir.$list['usersAvatar']; ?>" class="publicAvatar" />
</div>
Name:<?php echo $name; ?> <br />
Bio:<?php echo $bio; ?> <br />
Stars: <?php echo $stars; ?> <br />
<?php
if ($currentUserLevel == 'pro') {
echo 'CONTACT SCOUT';
}
else {
echo 'Sorry you must upgrade to a Pro membership to contact this Scout';
}
?>
</div>
</div>
<?php }
?>
</div>
</div>
</div>
</div>