Page 1 of 1

displaying all rows from db

Posted: Mon Jan 23, 2006 5:54 pm
by dru_nasty
I've used code like this quite a few times with no problem.

I'm trying to display all the rows in a table called news.
I know there is data in there as well.
When I test it only shows the most recent entry.
Am I missing something?

Code: Select all

$sql = "SELECT * FROM news"; 
$result = mysql_query($sql, $conn) or die(mysql_error()); 
while ($newArray = mysql_fetch_array($result)){
$headline = $newArray ['headline'];
$content = $newArray ['content'];
$time = $newArray ['date_added'];
}
echo "$headline,$content,$time <br \>";

Posted: Mon Jan 23, 2006 5:59 pm
by Christopher
I should be:

Code: Select all

while ($newArray = mysql_fetch_assoc($result)){

Posted: Mon Jan 23, 2006 6:07 pm
by dru_nasty
that didn't do it. :(

Posted: Mon Jan 23, 2006 6:08 pm
by feyd
move the echo into the loop. ;)

Posted: Mon Jan 23, 2006 6:18 pm
by dru_nasty
yep, I just saw that.
Thanks! :D