Building an associative array form DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Building an associative array form DB

Post by GeXus »

I have a table with the following:

id, name, user, pass, date

I want select from it and format it so it returns like this....

Code: Select all

$val = array("id" => 1,
             "name" => "person",
             "user" => "persons name",
             "pass" => "persons pass",
             "date" => ""
            );
This way I can use json_encode and have it formatted properly.... how would I set it up to return an array formatted like that?
programmingjeff
Forum Commoner
Posts: 26
Joined: Fri Jan 05, 2007 10:56 am

Post by programmingjeff »

$val = mysql_fetch_assoc($resource);
Post Reply