Re: MySQL result to Associative array
| From: | Jason Wong | Date: | Mon, 21 Oct 2002 14:22:40 +0000 |
| Subject: | Re: MySQL result to Associative array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-120736@lists.php.net to get a copy of this message | ||
On Monday 21 October 2002 21:43, Tony Crockford wrote:
> Hi all
>
> how do I turn a two column table into MySQL into an Associative array?
>
> I've tried this:
>
> $md_query = "SELECT * FROM md_def order by md_ref asc";
> $md_result= mysql_query($md_query) or die ("Error in query: $md_query. "
> . mysql_error());
>
> while ($row = mysql_fetch_array($md_result))
>
> {
>
> $md_ref=$row['md_ref'];
> $md_title=$row['md_title'];
>
> $myarray['$md_ref']=$md_title;
You don't want to use single-quotes, use:
$myarray[$md_ref]=$md_title;
> }
>
> but I can't read out of the array like this:
>
> echo $myarray['1'];
>
> where am I going wrong?
--
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
/*
For fools rush in where angels fear to tread.
-- Alexander Pope
*/