Just a little picture

April 21, 2010

PHP/MySQL: extract a numerically indexed array

Because I had a hard time finding this simple answer, I am leaving myself a note here: How to get a numerically indexed array out of a MySQL database with PHP:

$result = mysql_query("SELECT `Some_Field` FROM `Table` WHERE (whatever...)");
$i=0;
while ($array = mysql_fetch_array($result))
{
$numerically_indexed_array_i_want[] = $array[0];
echo $i." ". $numerically_indexed_array_i_want[$i]."<br>";
$i++;
}
/****** Verify that the array has been populated properly ******/
echo "<pre>" . print_r($numerically_indexed_array_i_want, true) . "</pre>";
Posted by Charles at 12:01 AM






Content licensed under
Creative Commons License