jck Posted July 12, 2007 Share Posted July 12, 2007 is this code correct???? $q="SELECT * FROM dd_rating WHERE ItemID = $ItemID AND username = '$_SESSION[username]"; $r2 = mysql_query($q); if (mysql_num_rows($r2) = 0) { echo '<b><center>You have not yet rated this joke </center></b><br>'; } else { echo '<b><center>You have given this joke a rating of ' . $rate = $row['Rating] . </center></b><br> ?> Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 12, 2007 Share Posted July 12, 2007 No. At the least ItemID = $ItemID ought to be ItemID = '$ItemID' and the $row array needs to be abstracted after the database query ... $row=mysql_fetch_array($r2); Quote Link to comment Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 oops $row=mysql_fetch_array($r2) but it dosent look like they are all the errors.... Quote Link to comment Share on other sites More sharing options...
jitesh Posted July 12, 2007 Share Posted July 12, 2007 $q="SELECT * FROM dd_rating WHERE ItemID = ".$ItemID ." AND username = '".$_SESSION[username]."'"; $r2 = mysql_query($q); if (mysql_num_rows($r2) == 0) { echo '<b><center>You have not yet rated this joke </center></b><br>'; } else { echo '<b><center>You have given this joke a rating of ' . $rate = $row['Rating] . </center></b><br> ?> Quote Link to comment Share on other sites More sharing options...
tapos Posted July 12, 2007 Share Posted July 12, 2007 try this $q="SELECT * FROM dd_rating WHERE ItemID = ".$ItemID ." AND username = '".$_SESSION[username]."'"; $r2 = mysql_query($q); if (!mysql_num_rows($r2)) { echo '<b><center>You have not yet rated this joke </center></b><br />'; } else { while($row = mysql_fetch_arrray($r2)) { echo '<b><center>You have given this joke a rating of ' . $rate = $row['Rating] .' </center></b><br />'; } } ?> Quote Link to comment Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 each guy can vote only once Quote Link to comment Share on other sites More sharing options...
tapos Posted July 12, 2007 Share Posted July 12, 2007 Now this will help u, $q="SELECT * FROM dd_rating WHERE ItemID = ".$ItemID ." AND username = '".$_SESSION[username]."'"; $r2 = mysql_query($q); if (!mysql_num_rows($r2)) { echo '<b><center>You have not yet rated this joke </center></b><br />'; } else { $row = mysql_fetch_arrray($r2)) echo '<b><center>You have given this joke a rating of ' . $rate = $row['Rating] .' </center></b><br />'; } ?> Quote Link to comment Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 none of there are working Quote Link to comment Share on other sites More sharing options...
jck Posted July 12, 2007 Author Share Posted July 12, 2007 its very puzzling i dont understand whats wrong with these codes Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 12, 2007 Share Posted July 12, 2007 Sigh. "None of these are working" really doesn't help anyone at all because we can't tell what's supposed to happen with your testing echo the value of $q immediately after defining it. Post exactly what it says. Quote Link to comment Share on other sites More sharing options...
Oldiesmann Posted July 13, 2007 Share Posted July 13, 2007 $q="SELECT * FROM dd_rating WHERE ItemID = ".$ItemID ." AND username = '".$_SESSION[username]."'"; $r2 = mysql_query($q); if (!mysql_num_rows($r2)) { echo '<b><center>You have not yet rated this joke </center></b><br />'; } else { $row = mysql_fetch_array($r2)) echo '<b><center>You have given this joke a rating of ' . $rate = $row['Rating'] .' </center></b><br />'; } ?> Two typos: One too many "r"s in "mysql_fetch_array" Missing a ' before ] in the last echo line. Quote Link to comment Share on other sites More sharing options...
jck Posted July 13, 2007 Author Share Posted July 13, 2007 i dont understand the page comes blank Quote Link to comment Share on other sites More sharing options...
jitesh Posted July 13, 2007 Share Posted July 13, 2007 Attach you php file Quote Link to comment Share on other sites More sharing options...
jck Posted July 13, 2007 Author Share Posted July 13, 2007 i ran it indivijually by putting a number and it didnt work Quote Link to comment Share on other sites More sharing options...
ankhmor Posted July 13, 2007 Share Posted July 13, 2007 this is the original code: $q="SELECT * FROM dd_rating WHERE ItemID = $ItemID AND username = '$_SESSION[username]"; $r2 = mysql_query($q); if (mysql_num_rows($r2) = 0) { echo '<b><center>You have not yet rated this joke </center></b><br>'; } else { echo '<b><center>You have given this joke a rating of ' . $rate = $row['Rating] . </center></b><br> ?> First mistake: $q="SELECT * FROM dd_rating WHERE ItemID = $ItemID AND username = '$_SESSION[username]"; Should be: $q="SELECT * FROM dd_rating WHERE ItemID = '$ItemID' AND username = '$_SESSION[username]'"; Second: if (mysql_num_rows($r2) = 0) Should be: if (mysql_num_rows($r2) == 0) third: what is $row? I think what you meant was $rate = mysql_result($r2, 0, 'Rating'); I fogot you can use mysql_fetch_row too. (but I never use it and not sure how to excactly) Quote Link to comment Share on other sites More sharing options...
jck Posted July 13, 2007 Author Share Posted July 13, 2007 <? $query="SELECT * FROM dd_rating WHERE ItemID = '114' AND username = 'jck'"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { echo '<b><center>You have not yet rated this joke </center></b><br>'; } else { $rate = mysql_result($result, 0, 'Rating'); echo '<b><center>You have given this joke a rating of ' . $rate . </center></b><br> ?> i tested with this code and i get blank page Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 14, 2007 Share Posted July 14, 2007 <?php $query="SELECT * FROM dd_rating WHERE ItemID = '114' AND username = 'jck'"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { echo '<b><center>You have not yet rated this joke </center></b><br>'; } else { $rate = mysql_result($result, 0, 'Rating'); echo '<b><center>You have given this joke a rating of ' . $rate . '</center></b><br>';// changed line } // closed loop ?> I can only assume your server does not have display errors active. Quote Link to comment Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 now i get you have not yet rated this joke for all.... Quote Link to comment Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 oops sorry its working 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.