Re: [Beginner] Very Basic DB usage question
| From: | Matthew Weier O'Phinney | Date: | Mon, 11 Jul 2005 01:50:24 +0000 |
| Subject: | Re: [Beginner] Very Basic DB usage question | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-19936@lists.php.net to get a copy of this message | ||
* (lse) <lstelie@gmail.com>:
> Hello,
>
> Sorry for upsetting you with such basic questions, but I'm starting..
>
> I have the following database table :
>
> id name
> 1 FOO
> 2 FOO2
> 3 FOO3
>
> I would need to get the content of this table in the same way
>
> array("id" "name")
>
>
> I succeed i getting very sophisticated arrays but no to get a basic one
> I get for example :
> Array
> (
> [0] => Array
> (
> [id] => 1
> [name] => FOO
> )
>
> [1] => Array
> (
> [id] => 2
> [name] => FOO2
> )
>
> .... and so on
Try:
$stuff = $db->getAssoc("SELECT id, name FROM stuff_table");
This will fetch all items from stuff_table and return them as an
associative array of id => name pairs.
--
Matthew Weier O'Phinney
Zend Certified Engineer
http://weierophinney.net/matthew/