Re: question - display rows

From: Date: Sat, 23 Mar 2002 02:46:13 +0000
Subject: Re: question - display rows
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-89803@lists.php.net to get a copy of this message
Hi, (untested code) <? $sql = "SELECT id,heading,message FROM news ORDER BY id DESC LIMIT 5; $result = @mysql_query($sql); while($myrow = mysql_fetch_array($result)) { echo $myrow["id"].$myrow["heading"].$myrow["message"]; } ?> or better still: <? $sql = "SELECT id,heading,message FROM news ORDER BY id DESC LIMIT 5; $result = @mysql_query($sql); while($myrow = mysql_fetch_array($result)) { foreach($myrow as $key => $value) { // convert $myrow["id"] to $id, etc etc for all fields // much easier to work with!! $$key=nl2br(stripslashes($value)); } echo $id.$heading.$message; } ?> Justin French --------------------- http://indent.com.au http://soundpimps.com http://hinge.net.au Phil Schwarzmann wrote: > > When I want to display a table onto the screen I use this code.... > > $query = "SELECT * FROM database"; > $result = mysql_query($query); > $num_rows = mysql_num_rows($result); > for ($i = 0; $i < $num_rows; $i++) { > $field1 = mysql_result($result, $i, field1); > $field2 = mysql_result($result, $i, field2); > echo $field1.$field2; > } > > ...but I heard that using mysql_result() is very ineffecient and that I > should be using mysql_fetch_array() instead. > > So how could produce those same results using mysql_fetch_array() > instead?? > > THANKS!! YOU GUYS ROCK!!!

« previous php.general (#89803) next »