Hi, I have a while loop that runs through the array but it doesnt echo the first row of data, it starts from the second. Any ideas why? My code is <?php $getfriends = "SELECT friendid FROM friends WHERE id = '$user_id'"; $gf = mysql_query($getfriends) or die(); $friendrow = mysql_fetch_array($gf); ?> Code (markup): <?php if (mysql_num_rows($gf) == 0) { echo $f_name . ' has no friends!' ; } else { while ($rowgf = mysql_fetch_array($gf, MYSQL_ASSOC)) { $getfriendid = $rowgf['friendid']; $getfname = "SELECT f_name, l_name FROM user WHERE id = '$getfriendid'"; $gfn = mysql_query($getfname) or die(); $rowf = mysql_fetch_array($gfn, MYSQL_ASSOC); { echo ($rowf["f_name"]); echo ($rowf["l_name"]); } } } ?> Code (markup): thanks, Gareth
Remove this line in the first block of code: $friendrow = mysql_fetch_array($gf); PHP: This fetches the first row, and the loop continues from the second. If you need this line there, then use a do-while loop. www.php.net/control-structures.do.while