Page 1 of 1

Wierd Mysql query problems

Posted: Thu Aug 17, 2006 9:05 am
by danharibo
Im getting some wierd results with mysql_query();
Im queryig my database:

Code: Select all

$titleq = "SELECT title FROM ".TBL_CONT." WHERE id = 125;"; 
$title = mysql_query($titleq);
$bodyq = "SELECT body FROM ".TBL_CONT." ;";
$body = mysql_query($bodyq);
but when i echo The contents of $body and $title i get this:
Resource id #15

Resource id #16
Witch is not what have in my database:
Welcome! Hello!. Unfortuanatly, We are Still under construc...
What is going wrong?

Posted: Thu Aug 17, 2006 9:08 am
by Z3RO21
try this

Code: Select all

$titleq = "SELECT title FROM `".TBL_CONT."` WHERE `id` = '125';";
$title = mysql_query($titleq);
$bodyq = "SELECT body FROM `".TBL_CONT."`;";
$body = mysql_query($bodyq);
I have had same here, and doing this has always fixed it for me.

Posted: Thu Aug 17, 2006 9:09 am
by JayBird
That is actually what it SHOULD output

try this

Code: Select all

$titleq = "SELECT title FROM ".TBL_CONT." WHERE id = 125;";
$title = mysql_query($titleq);

$row = mysql_fetch_array($title, MYSQL_ASSOC)

echo $row['title'];

$bodyq = "SELECT body FROM ".TBL_CONT." ;";
$body = mysql_query($bodyq); 

$row = mysql_fetch_array($body, MYSQL_ASSOC)

echo $row['body'];

Posted: Thu Aug 17, 2006 9:10 am
by Z3RO21
Oh, good call JayBird I didn't even notice he was puting out the resource IDs hehe.

Posted: Thu Aug 17, 2006 9:10 am
by feyd
mysql_query() returns a result resource, a hook for MySQL to return records from. Use one of the mysql_fetch_* functions to retrieve the first record it found or a loop calling mysql_fetch_* mutliple times to retrieve all records found.

Posted: Thu Aug 17, 2006 9:22 am
by danharibo

Code: Select all

echo $row['title'];
Causes a Parse Error

Posted: Thu Aug 17, 2006 9:26 am
by JayBird
oooops, i forgot a closing semi-colon (;) on both these lines

Code: Select all

$row = mysql_fetch_array($body, MYSQL_ASSOC)
Image

Posted: Thu Aug 17, 2006 9:33 am
by danharibo
well, thanks for your help, now i can get back to adding more features to my Custom cms thing