PDA

View Full Version : retrieving info from a db


Dimava
Sun 26th May '02, 2:17am
$result = mysql_query(" SELECT catgroup FROM tutorials WHERE id=$id ");
list($catgroup) = mysql_fetch_row($result);
print "the category is $catgroup";

if (!mysql_query($result)) {
echo "QUERY ERROR1: " . mysql_error() . "\n";
}


when I run this, it gives me this error:

the category is QUERY ERROR1: You have an error in your SQL syntax near 'Resource id #2' at line 1

thanks

Dimava

Scott MacVicar
Sun 26th May '02, 7:49am
$result = mysql_query("SELECT catgroup FROM tutorials WHERE `id`='$id'");

try that

Chen
Sun 26th May '02, 8:11am
The error you provided is not very descriptive, but I assume $id contains 'Resource id #2' which causes the error. Make sure $id is correctly fetched.

Dimava
Sun 26th May '02, 3:11pm
PPN: nope it didn't work :(

FireFly: the $id is an integer, I made it print the $id before, and it came up correctly

-Dimava

Dan615
Sun 26th May '02, 3:26pm
try changing the variable name if $id to something else...like $idx or something, you might have conflicting variable names

edit: can you show us more of the script?

Chen
Sun 26th May '02, 3:27pm
Echo the query and see how it looks like.

Dan615
Sun 26th May '02, 3:29pm
Wait, I found the problem:

if (!mysql_query($result)) {
echo "QUERY ERROR1: " . mysql_error() . "\n";
}

$result is the identifier to the last query at the top...and its value is a string, "Resource ID #2"

are you sure you didn't mean...


if (!mysql_num_rows($result)) {


or


if (!$result) {