Jump to content

Retrieving Results from MySQL inserting into Array


lilman

Recommended Posts

My objective:  I have a SELECT query that will select rows from a table in my database.  I would like to put the results from the query into a numeric array (I am thinking it is going to need to be a multidimensional array).  The array needs to store the column values, maybe it would look something like this:

$users = array
(
"1"=>array // auto increment
(
  "$id", // column from database
  "$path", // column from database
  "$score", // column from database
),

"2"=>array // auto increment
(
  "$id", // column from database
  "$path", // column from database
  "$score", // column from database
),
);

My hurtle:  I am not sure how to put my results in an array like the one above (if that is even the best way to do this).

If someone could help me out that would be terrific, thank you
do you plan to output all the information immediately?
if so you could:
[code]
$query=@mysql_query("select id, path, score from table");
while($row=mysql_fetch_array($query))
{
    echo $row[0];  //id
    echo $row[1];  //path
    echo $row[2];  //score
}
[/code]

the while will loop until it reaches the end of the array, aka all the users.

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.