supanoob Posted April 26, 2009 Share Posted April 26, 2009 i have the following loop to echo comments, basically it all works perfectly except for the fact that the comment_name isnt getting echoed and i cant see why, the comment_by_id is there perfect so im guessing it has something to do with the query for the name, however all pieces of data are correct, the query is going through its just not returning any rows. <?php $query="select comment_by, comment, comment_date, comment_time from comments where comment_on='website' AND comment_on_id='$siteid' ORDER BY comment_id DESC LIMIT 10"; $result=mysql_query($query); if (!$result) { die(mysql_error()); } $num_rows=mysql_num_rows($result); $li=1; while ($row=mysql_fetch_array($result)) { $comment_by=($row['comment_by']); $comment=($row['comment']); $comment_time=($row['comment_time']); $comment_date=($row['comment_date']); $query1="select user_username from user_accounts where user_id='$comment_by'"; $result1=mysql_query($query1); if (!$result) { die(mysql_error()); } $num_rows=mysql_num_rows($result1); $row=mysql_fetch_array($result1); $comment_name=($row['user_username']); echo "<form><table style=\"width: 100%\"> <tr> <td colspan=\"2\" class=\"form\"><b>Posted By:</b> $comment_name <b>At:</b> $comment_time <b>On:</b> $comment_date</td> </tr> <tr> <td style=\"width: 110px; height: 110px\" class=\"tform\">Comment No: $li<img src=\"/thehub/images/webshots/no_screenshot.jpg\"></td> <td valign=\"top\" class=\"website\"><b>Comment:</b><br>$comment</td> </tr> <tr> <td colspan=\"2\" class=\"form\">[Add][Mail][Chat icons]</td> </tr> </table></form> "; $li++; } ?> Link to comment https://forums.phpfreaks.com/topic/155710-solved-simple-solution/ Share on other sites More sharing options...
mrMarcus Posted April 26, 2009 Share Posted April 26, 2009 so, what are you asking? Link to comment https://forums.phpfreaks.com/topic/155710-solved-simple-solution/#findComment-819588 Share on other sites More sharing options...
wildteen88 Posted April 26, 2009 Share Posted April 26, 2009 You said comment_by_id works. However you're selecting a column called comment_by. Are these the same? Add the following echo 'The query: <pre>'.htmlentities($query1).'</pre> returned '. $num_rows . 'rows'; after: $result1=mysql_query($query1); if (!$result) { die(mysql_error()); } $num_rows=mysql_num_rows($result1); To check if your second query is returning any result and that the query is being constructed correctly. Link to comment https://forums.phpfreaks.com/topic/155710-solved-simple-solution/#findComment-819589 Share on other sites More sharing options...
supanoob Posted April 26, 2009 Author Share Posted April 26, 2009 You said comment_by_id works. However you're selecting a column called comment_by. Are these the same? Add the following echo 'The query: <pre>'.htmlentities($query1).'</pre> returned '. $num_rows . 'rows'; after: $result1=mysql_query($query1); if (!$result) { die(mysql_error()); } $num_rows=mysql_num_rows($result1); To check if your second query is returning any result and that the query is being constructed correctly. comment_by is what i meant and the code you gave me returned: The query: select user_username from user_accounts where user_id=2 returned 0rows Link to comment https://forums.phpfreaks.com/topic/155710-solved-simple-solution/#findComment-819591 Share on other sites More sharing options...
supanoob Posted April 26, 2009 Author Share Posted April 26, 2009 so, what are you asking? im asking why the name doesnt show Link to comment https://forums.phpfreaks.com/topic/155710-solved-simple-solution/#findComment-819594 Share on other sites More sharing options...
wildteen88 Posted April 26, 2009 Share Posted April 26, 2009 Theres your problem. Your second query is not able find a user_id of 2 within your user_accounts table, thus why $comment_name does not display anything when you echo it. Link to comment https://forums.phpfreaks.com/topic/155710-solved-simple-solution/#findComment-819595 Share on other sites More sharing options...
mrMarcus Posted April 26, 2009 Share Posted April 26, 2009 so, map out your query .. look in your db table 'user_accounts', is there a user_id #2? if so, is there a user_username for that record? Link to comment https://forums.phpfreaks.com/topic/155710-solved-simple-solution/#findComment-819596 Share on other sites More sharing options...
supanoob Posted April 26, 2009 Author Share Posted April 26, 2009 Theres your problem. Your second query is not able find a user_id of 2 within your user_accounts table, thus why $comment_name does not display anything when you echo it. sorted it thanks Link to comment https://forums.phpfreaks.com/topic/155710-solved-simple-solution/#findComment-819598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.