Re: MySQL query to generate Array
| From: | Luis Moreira | Date: | Mon, 22 Mar 2004 16:33:43 +0000 |
| Subject: | Re: MySQL query to generate Array | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-23225@lists.php.net to get a copy of this message | ||
Try something like this (UNTESTED)
// array1 is temporary array
// array2 is the one to fill with query results
$array1= array("URL"=>"nul","URLN"=>"nul");
$array2= array(
1=>array("URL"=>"","URLN" => "")
);
// $n is counter of registers
// begin mysql query
// foreach element
// $row[0] is URL
// $row[1] is URLN
if ($n==0) {
$array2[1]["URL"] = $row[0];
$array2[1]["URLN"] = $row[1];
} else
{
$array2[1]["URL"] = $row[0];
$array2[1]["URLN"] = $row[1];
array_push ($array2,$array1[1]);
}
// end foreach
// Example
// $array2[10]["URL"] now contains the 10th URL value
// $array2[10]["URLN"] now contains the 10th URLN value
----- Original Message -----
From: "Tony Devlin" <tdevlin@airewaves.com>
To: <php-windows@lists.php.net>
Sent: Monday, March 22, 2004 3:04 PM
Subject: [PHP-WIN] MySQL query to generate Array
How do you setup a mysql query to generate an array?
I want to take URL and URLName from a database and use it to create an array
called links.
I know how to do the array and the mysql seperately, I don't know how to
make the results of
the mysql become the key=>value pairs in the array.
Any help is appreciated
--Tony