views:

31

answers:

1

If I have a database with the structure:

___id_____|____value____
   1      |    value1
   2      |    value2
   3      |    value3

How can I pull data from this MySQL database in PHP and have it formatted like this:

Array ( [0] => stdClass Object ( [id] => 1 [value] => value1 ) [1] => stdClass Object ( [id] => 2 [value] => value2 ) [2] => stdClass Object ( [id] => 3 [value] => value3 ) )
+3  A: 

You can use the mysql_fetch_object() function instead of mysql_fetch_array() and manually create new objects.

Read more about it here: http://php.net/manual/en/function.mysql-fetch-object.php

Sergey Kuznetsov
Wow. I had completely forgotten about that function. Even easier than casting a result array. +1.
zombat