Jason Jason - 5 months ago 20
SQL Question

Storing data from SQL in array

I am trying to store the data from my sql database into an array. Currently I have this:

$query = mysql_query("SELECT * FROM `InspEmail` WHERE `Company` LIKE '$company'");

while($row = mysql_fetch_array($query))
{

$inspector = $row['name'];

}


The problem is that I have 8 rows of data. I need to store each 8 names from that database into an array. When I try this:

$inspector = array($row['name']);


It doesn't work.

Answer

What you want is:

$inspector[] = $row['name'];

This will store all 8 names in an array similar to:

array(
     [0] => name1
     [1] => name2
     [2] => name3

)
Comments