Re: Using two colomns of mysql data as key/value pairs in arrays
| From: | David T-G | Date: | Mon, 20 Oct 2003 14:05:53 +0000 |
| Subject: | Re: Using two colomns of mysql data as key/value pairs in arrays | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-31164@lists.php.net to get a copy of this message | ||
Chris --
..and then Chris Boget said...
%
% > The original poster actually mentioned an associative array with one db
% > field as the index and another as the value. None of these, just like
% > Ignatius's suggestion, will do the job.
%
% Actually, mysql_fetch_assoc() will do quite nicely.
Really? How? I must be quite confused.
Given a DB table that looks about like
id name
01 david
02 anna
03 eunice
04 bob
05 celeste
06 fred
then code like
$result = mysql_query("select id,name from table") ;
while ( $row = mysql_fetch_assoc($result) ) // or mysql_fetch_array($result,MYSQL_ASSOC) for those
who like mysql_fetch_array but for some reason care about the memory used by a single record
{
...
}
will yield $row like
array
(
'id' => 01,
'name' => 'david'
)
or so every time. How on earth is that going to get Devon his desired
array
(
'01' => 'david' ,
'02' => 'anna' ,
...
)
as requested without some php work?
%
% > I didn't think it worth shooting down someone who was being helpful, though,
% > when I made my response.
%
% It didn't seem like he was shooting you down.
No, but IMNSHO he shot a rather rude hole in Ignatius.
%
% Chris
TIA & HTH & HAND
:-D
--
David T-G * There is too much animal courage in
(play) davidtg@justpickone.org * society and not sufficient moral courage.
(work) davidtgwork@justpickone.org -- Mary Baker Eddy, "Science and Health"
http://justpickone.org/davidtg/ Shpx gur
Pbzzhavpngvbaf Qrprapl Npg!