neex1233 Posted October 24, 2009 Share Posted October 24, 2009 I have this bit of code which is supposed to be selecting all records from a table. Here: $sql = " SELECT * FROM `messages` WHERE `to` = '$username' "; $result = mysql_query($sql) or die (mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $subject = $row['subject']; $from = $row['from']; $id = $row['id']; $time = $row['time']; } It works but it is only selecting one of the records that is to that user(first one), then when that one is deleted it is showing the next record to them. What should I do? I just want it to show all records in the table that have their username for the 'to' field. Thanks! Link to comment https://forums.phpfreaks.com/topic/178848-php-array/ Share on other sites More sharing options...
cags Posted October 24, 2009 Share Posted October 24, 2009 That code doesn't output anything so it's a bit difficult to say, my guess is directly after that loop your are outputting $subject, $from, $id and $time, which means you will only ever get the values of the last item in the database. You would need to make your output part of the loop or store the variables in an array and output them by making another loop. Link to comment https://forums.phpfreaks.com/topic/178848-php-array/#findComment-943524 Share on other sites More sharing options...
longtone Posted October 24, 2009 Share Posted October 24, 2009 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $entry[] =$row; } Link to comment https://forums.phpfreaks.com/topic/178848-php-array/#findComment-943532 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.