[PHP] Only displays 1 comment [FIXED]

Joined
Jun 8, 2007
Messages
1,961
Reaction score
475
My comments box should list all the comments for my users.
The problem is that only 1 comment displays, and it should display the first 50. There are no errors recorded, and the data is in the SQL table, but only 1 is displaying. If I change order to ASC, it shows the first comment, and DESC, it shows the last comment. This works great, it tells me that the code is finding the data, but it is not displaying all of it. I can't figure out why my array isn't displaying all my rows :scratch:
PHP:
<?php 
       print '<tr><td width="431" height="19" align="left" valign="top">';
       //Comments
       //Get data from database for comments.
$getdata="SELECT * from `comments` WHERE `friendID` = '$userID' ORDER BY `entryID` DESC LIMIT 50";
$getdata2=mysql_query($getdata) or die("Could not get comment data");
//Fetch the data from the database.
while($getdata3=mysql_fetch_array($getdata2))
{
//Convert SQL to PHP.
  $getdata3[myID]=strip_tags($getdata3[myID]);
  $getdata3[title]=strip_tags($getdata3[title]);
  $getdata3[comment]=strip_tags($getdata3[comment]);
  $getdata3[date]=strip_tags($getdata3[date]);
  $friendID=$getdata3['myID'];
  $title=$getdata3['title'];
  $comment=$getdata3['comment'];
  $date=$getdata3['date'];
 
  //Get Sender Data.
$getdata="SELECT * from `users` WHERE `userID` = '$friendID' LIMIT 1 ";
$getdata2=mysql_query($getdata) or die("Could not get sender data");
//Fetch the data from the database.
while($getdata3=mysql_fetch_array($getdata2))
{
//Convert SQL to PHP.
  $getdata3[display_name]=strip_tags($getdata3[display_name]);
  $getdata3[username]=strip_tags($getdata3[username]);
  $getdata3[myImageURL]=strip_tags($getdata3[myImageURL]);
  if(strlen($getdata3['display_name'])>1) {
  $senderName=$getdata3['display_name'];
  } else {
  $senderName=$getdata3['username'];
  }
  $senderImg=$getdata3['myImageURL'];
  $senderUser=$getdata3['username'];
  if(strlen($senderImg)<10) {
  $senderImg=$defaultImg;
  }
  //close Sender Data
  }
 if(strlen($total)<1) {
 $total=1;
 } else {
 $total=$total+1;
 }
  print "</td></tr><tr><td align='center' valign='top' width='30%' style='border-right-style: solid; border-right-width: thin; border-right-color:#4B6294; border-top-style: solid; border-top-width: thin; border-top-color: #4B6294;'>";
  print "<a href='profile.php?username=$senderUser' target='_self'>$senderName<br><img src='$senderImg' height='75' width='75' border='0' /></a></td>";
  print "<td align='left' valign='top' width='70%' style='border-top-style: solid; border-top-width: thin; border-top-color: #4B6294;'>";
  print "<h3>$title</h3><p>$comment</p><p align='left'><small><i>$date   </small></i></p>";
 
    //closing Comment data
  }
  print ' </td></tr>';
  print "<tr><td align='center' valign='top' width='30%' style='border-right-style: solid; border-right-width: thin; border-right-color:#4B6294; border-top-style: solid; border-top-width: thin; border-top-color: #4B6294;'> <a href=\"#\" onclick=\"javascript:popUpWindow('postComment.php?username=". $_REQUEST['username'] ."','200','200','350','350')\">Post Comment</a></td><td align='left' valign='top' width='70%' style='border-top-style: solid; border-top-width: thin; border-top-color: #4B6294;'> Total Comments: $total</td>";
        ?>

EDIT: I found my mistake.. I used the same $getdata, $getdata2, $getdata3 varriables twice. That's why it wasn't working..
(That's what I get for copy & Pasting lol)
New Code:
PHP:
<?php 
					  print '<tr><td width="431" height="19" align="left" valign="top">';
					  //Comments
					  //Get data from database for comments.
$getdata="SELECT * from `comments` WHERE `friendID` = '$userID' ORDER BY `entryID` DESC LIMIT 50";
$getdata2=mysql_query($getdata) or die("Could not get comment data");

//Fetch the data from the database.
while($getdata3=mysql_fetch_array($getdata2))
{
//Convert SQL to PHP.
  $getdata3[myID]=strip_tags($getdata3[myID]);
  $getdata3[title]=strip_tags($getdata3[title]);
  $getdata3[comment]=strip_tags($getdata3[comment]);
  $getdata3[date]=strip_tags($getdata3[date]);
  $friendID=$getdata3['myID'];
  $title=$getdata3['title'];
  $comment=$getdata3['comment'];
  $date=$getdata3['date'];
  
  //Get Sender Data.
$getdata4="SELECT * from `users` WHERE `userID` = '$friendID' LIMIT 1 ";
$getdata5=mysql_query($getdata4) or die("Could not get sender data");

//Fetch the data from the database.
while($getdata6=mysql_fetch_array($getdata5))
{
//Convert SQL to PHP.
  $getdata6[display_name]=strip_tags($getdata6[display_name]);
  $getdata6[username]=strip_tags($getdata6[username]);
  $getdata6[myImageURL]=strip_tags($getdata6[myImageURL]);
  if(strlen($getdata6['display_name'])>1) {
  $senderName=$getdata6['display_name'];
  } else {
  $senderName=$getdata6['username'];
  }
  $senderImg=$getdata6['myImageURL'];
  $senderUser=$getdata6['username'];
  if(strlen($senderImg)<10) {
  $senderImg=$defaultImg;
  }
  //close Sender Data
  }
 if(strlen($total)<1) {
 $total=1;
 } else {
 $total=$total+1;
 }
  print " </td></tr><tr><td align='center' valign='top' width='30%' style='border-right-style: solid; border-right-width: thin; border-right-color:#4B6294; border-top-style: solid; border-top-width: thin; border-top-color: #4B6294;'>";
  print "<a href='profile.php?username=$senderUser' target='_self'>$senderName<br><img src='$senderImg' height='75' width='75' border='0' /></a></td>";
  print "<td align='left' valign='top' width='70%' style='border-top-style: solid; border-top-width: thin; border-top-color: #4B6294;'>";
  print "<h3>$title - <small><i>$date   </small></i></h3><p>$comment</p>";
  	
    //closing Comment data
  }
  print ' </td></tr>';
  print "<tr><td align='center' valign='top' width='30%' style='border-right-style: solid; border-right-width: thin; border-right-color:#4B6294; border-top-style: solid; border-top-width: thin; border-top-color: #4B6294;'> <a href=\"#\" onclick=\"javascript:popUpWindow('postComment.php?username=". $_REQUEST['username'] ."','200','200','350','350')\">Post Comment</a></td><td align='left' valign='top' width='70%' style='border-top-style: solid; border-top-width: thin; border-top-color: #4B6294;'> Total Comments: $total</td>";
					   ?>
 
Last edited:
Back