You are here: Re: mysql table into associated array HOWTO?? « All PHP « IT news, forums, messages
Re: mysql table into associated array HOWTO??

Posted by mbocquet on 10/13/56 11:29

p cooper wrote:
> Sorry if this isnt the correct place- I cant find an obvious PHP/MySQL NG
>
> A 2 column table and i want row 1 to be the key and row 2 to be the value
> $result = mysql_query("SELECT * FROM table");
> while($row=mysql_fetch_row($result)){
>
> $array['$row[0]']=$row[1]
> }
> which doesnt work .
>
>
> im after the equivalent (in perl) of keys%array and values%array functions

I was just searching the way to do this and landed here.

You should replace ' by " or remove them... then it works

while ($row=mysql_fetch_row($result))
$array["$row[0]"]=$row[1];
or
$array[$row[0]]=$row[1];

print_r($array);

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация