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!!!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to