Fill mySQL table to PHP matrix

Asked By 30 points N/A Posted on -
qa-featured

Is there a method to fill from one column of mySQL table to a PHP Matrix (array).

Any help would be much appreciated.

 

SHARE
Best Answer by Luker Malcom
Answered By 0 points N/A #147276

Fill mySQL table to PHP matrix

qa-featured

Hi Elias Cooper,

Hope that my message finds you well.

From my experience in PHP I didn’t face this case but I have searched in (stack overflow) site and this may help you.

You can check the following URL:

https://stackoverflow.com/questions/1538229/create-php-array-from-mysql-column

Also you can take a look at the following URL:

https://stackoverflow.com/questions/10668680/php-fill-array-from-multiple-sources

Hope that this will help you.

Thanks,

 

Best Answer
Best Answer
Answered By 5 points N/A #147277

Fill mySQL table to PHP matrix

qa-featured

 

Yes there is a way to do that. First, create a temporary storage where you will put the data you will be getting from your MySQL table. Say for example you choose $temp.

$temp = mysql_query (‘select * from table’);

Now you have to create another temporary storage for the array and for this, we will be using the same $temp to make a loop.

$temp = array ();

A condition is needed at this point. The condition’s logic should be like this: if you get a result from the query you made in $temp, it should be stored in an array and for each result you get, there is a corresponding array for that. It should look something like this:

While ($a = mysql_fetch_array ($temp)) {

Foreach ($a as $a1=>$b1) {

                   $temp [$a1] = $b1;

          }

          array_push ($temp);

          unset($temp);

}

 

Related Questions