Wierd Mysql query problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Wierd Mysql query problems

Post 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?
Z3RO21
Forum Contributor
Posts: 130
Joined: Thu Aug 17, 2006 8:59 am

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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'];
Z3RO21
Forum Contributor
Posts: 130
Joined: Thu Aug 17, 2006 8:59 am

Post by Z3RO21 »

Oh, good call JayBird I didn't even notice he was puting out the resource IDs hehe.
Last edited by Z3RO21 on Thu Aug 17, 2006 9:11 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post by danharibo »

Code: Select all

echo $row['title'];
Causes a Parse Error
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

oooops, i forgot a closing semi-colon (;) on both these lines

Code: Select all

$row = mysql_fetch_array($body, MYSQL_ASSOC)
Image
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post by danharibo »

well, thanks for your help, now i can get back to adding more features to my Custom cms thing
Post Reply