tommyda Posted January 20, 2009 Share Posted January 20, 2009 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 More sharing options...
DeanWhitehouse Posted January 20, 2009 Share Posted January 20, 2009 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'") Link to comment https://forums.phpfreaks.com/topic/141641-please-help-with-rating-system/#findComment-741440 Share on other sites More sharing options...
tommyda Posted January 21, 2009 Author Share Posted January 21, 2009 Fixed the errors that blade pointed out but im still getting the same problem Link to comment https://forums.phpfreaks.com/topic/141641-please-help-with-rating-system/#findComment-741753 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.