displaying all rows from db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

displaying all rows from db

Post 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 \>";
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I should be:

Code: Select all

while ($newArray = mysql_fetch_assoc($result)){
(#10850)
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

Post by dru_nasty »

that didn't do it. :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

move the echo into the loop. ;)
dru_nasty
Forum Commoner
Posts: 81
Joined: Sat Sep 10, 2005 10:26 am

Post by dru_nasty »

yep, I just saw that.
Thanks! :D
Post Reply