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> Quote Link to comment 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'") Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.