Skip to content
Advertisement

Selecting one row from MySQL using mysql_* API

I have the following query:

JavaScript

and the output I am getting is:

Resource id #2

Ultimately, I want to be able to echo out a single field like so:

JavaScript

Without having to use a while loop, as since I am only trying to get one field I do not see the point.

I have tried using mysql_result with no luck either.

Where am I going wrong?

Advertisement

Answer

Try with mysql_fetch_assoc .It will returns an associative array of strings that corresponds to the fetched row, or FALSE if there are no more rows. Furthermore, you have to add LIMIT 1 if you really expect single row.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement