While loop returning only one result !

Discussion in 'PHP' started by xkaser101, Aug 23, 2011.

  1. #1
    :confused: Hello,

    I have stumbled upon this wierd error and i can't seem to figure it out, Basicly I am using a while loop to retrieve all replies from my MySql table but it only return 1 record can you please examine my code and tell me why ? I really need it

    
    $r = mysqli_query($db_con_forum,"SELECT `message`, `user_id`, `post_id` FROM `posts` WHERE `parent_id` = '$post_id' "); // Selecting replies.
    if($r){
    	while($reply = mysqli_fetch_array($r, MYSQLI_ASSOC)){
    		$r = mysqli_query($db_con_users, "SELECT `nickname`,`points`,DATE_FORMAT(reg_date, '%b - %Y') AS date FROM `profile` WHERE `id` = '{$reply['user_id']}' ");
    		$user = mysqli_fetch_assoc($r);
    
    		echo "<div id=\"spacer_post\" style=\"clear:both\" >
    		<b><i>" . ucfirst($user['nickname']) . "</i></b><br /><br />";
    		echo "<i>Points : {$user['points']}</i><br />";
    		echo "<p style=\"\"><i>Joined : {$user['date']}</i></p><br />";	
    		echo "<a href=\"#reply\" onDragStart=\"return false;\" onSelectStart=\"return false;\"><img id=\"ReplyBtn\" src=\"../images/forum/reply.gif\" /></a>";
    		echo "</div>";
    	echo "<img id=\"spacer_img\" src=\"../images/forum/end.gif\" height=\"100\" width=\"2\" />";
    		echo "<p id=\"reply_message\">{$reply['message']}</p>";	
    	
    	} // display the add reply form.
    
    Code (markup):
    PS : the table already have more than one reply don't worry about that :)

    Thanks in advance,
    Kind Regards,
    Issa Shamoun.:cool:
     
    Solved! View solution.
    xkaser101, Aug 23, 2011 IP
  2. #2
    change $r in this query inside while loop to something else :) i/e $r2 :D because now it overwrites previous results and thats why you get only one
     
    tiamak, Aug 23, 2011 IP
  3. xkaser101

    xkaser101 Peon

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Many thank hehe :) +rep
     
    xkaser101, Aug 23, 2011 IP