Jump to content

accessing mysql_fetch_array


Guardian-Mage

Recommended Posts

$count     = "SELECT latest_id FROM cm_latest ORDER BY ABS(latest_id) LIMIT 2";
$count_out = mysql_query($count)
        	or die("This script was unable to execute the SQL Query Count. Please
        	contact the webmaster and inform them of the problem. Sorry for the
       		inconvience.");
$numrows1 = mysql_num_rows($count_out);

$query1   = "SELECT latest_id FROM cm_latest ORDER BY ABS(latest_id) LIMIT 2";
$result1  = mysql_query($query1)
        	or die("This script was unable to execute the SQL Query #1. Please
        	contact the webmaster and inform them of the problem. Sorry for the
       		inconvience.");
$object1  = mysql_fetch_array($result1);
extract($object1);

echo $latest_id[0];
echo "<br />";
echo $latest_id[1];
echo "<br />";
echo $numrows1;
exit();

 

That doesn't work. It doesn't print the value of latest_id[1].

I retrieved two rows and two values, how do I access the second value?

Link to comment
https://forums.phpfreaks.com/topic/53910-accessing-mysql_fetch_array/
Share on other sites

try

<?php
$query1   = "SELECT latest_id FROM cm_latest ORDER BY ABS(latest_id) LIMIT 2";
$result1  = mysql_query($query1)
        	or die("This script was unable to execute the SQL Query #1. Please
        	contact the webmaster and inform them of the problem. Sorry for the
       		inconvience.");
$latest_id = array();
while ($object1  = mysql_fetch_array($result1)) {
    $latest_id[] = $object[0];
}


echo $latest_id[0] ;
echo '<br>' ;
echo $latest_id[1] ;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.