Forum Moderators: coopster

Message Too Old, No Replies

Fetch a single value from a Mysql table

         

turbohost

12:01 pm on Jun 10, 2006 (gmt 0)

10+ Year Member



Hi Guys,

This is a very simple question but I can't find the answer anywhere. I'm looking for a way to fetch via PHP a single value from a Mysql table. For example I want to fetch the name of the member with id '23' from the table 'members'. I always find a solution for an array but I just want to fetch this single value. Can someone help me with this simple question?

I'm using this code right now but, although the query works, it doesn't give me a result.

$query="select name,url from general where pid='22' limit 1";
$result = mysql_query($query) or die();
$name = $result[name];

Thx,
Turbo

dreamcatcher

12:34 pm on Jun 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi turbohost,

The problem is you aren`t using any of the MySQL operators to return the value, you are simply testing the query. For single queries I use mysql_fetch_object().


$query="select name,url from general where pid='22' limit 1";
$result = mysql_query($query) or die();
$row = mysql_fetch_object($result);

$name = $row->name;

dc