MYSQL QUERY

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

MYSQL QUERY

Post by Parody »

I have a mysql query that selects something from the database and outputs it as a variable. It is a number and when outputed holds the value 'Resource id #5'. The row in the table is not fifth. And overall holds no significance (that i can see) to the number 5. This is the query:

Code: Select all

$query1455 = "SELECT mything FROM stats WHERE username= '$user'";
$user is a session that I set as a variable :)

Any ideas please?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

You've probably forgotten to fetch data from the resultset resource...

Code: Select all

$query = "SELECT mything FROM stats WHERE username='$username'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
if ($row)
{
  print_r($row);
}
else
{
  echo "no data was returned";
}
Post Reply