Displaying multiple rows of data from the database
Posted: Tue Feb 08, 2011 3:08 pm
I'm trying to display messages sent to users I have saved on the database, this is my code:
It seems right to me, but for some reason I am not getting any results. Any ideas as to what I'm doing wrong here?
(Also, I do have a proper connection to the database and my session is working correctly)
Code: Select all
<?php
$username = $_SESSION['username'];
$sql = mysql_query("SELECT * FROM mail WHERE to_user = '$username'") or die (mysql_error());
while($row = mysql_fetch_array($sql)){
echo $row['to_user'];
echo $row['from_user'];
echo $row['subject'];
echo $row['message'];
}
?>(Also, I do have a proper connection to the database and my session is working correctly)