Jump to content

[SOLVED] Simple solution?


supanoob

Recommended Posts

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

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.

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

 

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.