Jump to content

Please help with rating system ???


tommyda

Recommended Posts

I am developing a user rating system for a project but I am having problems.

 

What the script below should do is display the rating for each review but instead it is displaying the same rating on each row.

 

 

hope that made sense, heres the code (I have commented where the problem is)

This is where the problem is:

while($rrow = mysql_fetch_array( $reviewq )) {
$u_id = $rrow['userid'];

$userrating = mysql_query("SELECT service_rating FROM ratings WHERE u_id = '$u_id' && s_id = $s_id")
or die(mysql_error());
$urrow = mysql_fetch_array($userrating);
$urating = $urrow['service_rating'];
echo '<a href="user_review.php?rid='.$rrow['id'].'">'.$rrow['title'].'</a> - User Rating: '.$urating.'</br>';

};

Full code:

<?
include 'inc/mysql_con.php';
$s_id = $_GET['sid'];
$siteq = mysql_query("SELECT * FROM sites WHERE id = '$s_id'") 
or die(mysql_error());
$reviewq = mysql_query("SELECT * FROM reviews WHERE s_id = '$s_id'") 
or die(mysql_error());
$srow = mysql_fetch_array( $siteq );
//$rrow = mysql_fetch_array( $reviewq );
?>
<head>
<title><? echo $srow['title'];?> Review</title>
</head>

<body>
<p>Site: <a href="<? echo $srow['url'];?>"><? echo $srow['name']; 

$ratingq = mysql_query("SELECT avg(service_rating) AS avg_rating FROM ratings WHERE s_id = '$s_id' ") 
or die(mysql_error());
$rarow = mysql_fetch_array( $ratingq );
$rounded = round($rarow['avg_rating']);

echo'</a> </br>Average Rating: '.$rounded.'/10';

?></p>
<p>Our Review: 
  <? echo $srow['desc'];?>
</p>
<p>User Reviews:</br> 
// This is where the problem is 
<? while($rrow = mysql_fetch_array( $reviewq )) {
$u_id = $rrow['userid'];

$userrating = mysql_query("SELECT service_rating FROM ratings WHERE u_id = '$u_id' && s_id = $s_id")
or die(mysql_error());
$urrow = mysql_fetch_array($userrating);
$urating = $urrow['service_rating'];
echo '<a href="user_review.php?rid='.$rrow['id'].'">'.$rrow['title'].'</a> - User Rating: '.$urating.'</br>';

};?>
</p>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/141641-please-help-with-rating-system/
Share on other sites

Have you even looked at your sql statement ?

 

 

$userrating = mysql_query("SELECT service_rating FROM ratings WHERE u_id = '$u_id' && s_id = $s_id")

 

Should be

$userrating = mysql_query("SELECT service_rating FROM ratings WHERE u_id = '$u_id' AND s_id = '$s_id'")

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.