I am trying to get the created date for a user.

But when I run the following query

($abc = db_query('SELECT {created} FROM users WHERE uid = 2');)

in php page, I get the following output for $abc.

"Resource id #323"

Can anybody help me to tell me why this is showing up, and how to get the correct created date from the db table.

Thanks.

Comments

dman’s picture

This is what you asked for and should expect.
The results of a db query are a query result object.
Iterate the resultset as usual.

  $resultset = db_query('SELECT {created} FROM users WHERE uid = 2');
  while ($obj = db_fetch_object($resultset)) {
    drupal_set_message(print_r($obj,1));
  }

See any other database lookups in any PHP code for more examples.

There are a bunch more options if you look at the API, like db_result() that does some shortcuts for you. It requires reading the docs or learning by example however.

.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |

styro’s picture

The query has the brackets around the wrong bit - they go around the table names not the column names:

eg:
SELECT created FROM {users} WHERE uid = 2

--
Anton