Friday, May 21, 2010

How can I use php to generate an array (associated or ordinary) from a mysql database?

$results = mysql_query(" select * from table_name ");


while($r = mysql_fetch_array( $results ))


{


//You have an associated array ($r) with the results of the database.


echo $r['name']; //Prints the value of column 'name'





//Then, if you want to create an ordinary array, do this:


static $i=0;


name[$i] = $r['name'];


$i++;


//And like that with all column names.


}


No comments:

Post a Comment