Jump to content

PHP Array


neex1233

Recommended Posts

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

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

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.