...

View Full Version : join over two tables throwing an error



husnamina
08-20-2006, 12:32 AM
hi
am trying to select from 2 tables by making joins and arrrgghhh :mad: i cant get it to work. pls help



$sql=select
topic_title,
topics.mod_id,
topic_creator,
topics.role,
topics.post_timestamp,
post_creator,
posts.role,
posts.post_timestamp
from
topics,
posts
where topics.topic_ic=posts.topic_id,
topics.mod_id=$mod ,
posts.post_timestamp
between '$start' and '$end'";



i tried running it in a vba sql tester thing thats how i got the msg below, but intially whn i run it it just says cannot connect

Syntax error in query expression 'topics.topic_ic=posts.topic_id, topics.mod_id=$mod , posts.post_timestamp between '$start' and '$end'"'.

guelphdad
08-20-2006, 12:39 AM
Did you try hard coding values in there for $start and $end? If so were the values returned what you expected?

husnamina
08-20-2006, 01:17 AM
what do u mean by hard coding is it to put direct values in the stmnt?

husnamina
08-20-2006, 01:21 AM
i echoed the sql stmnt
and this it below
select topic_title, topics.mod_id, topic_creator, topics.role, topics.post_timestamp, post_creator, posts.role, posts.post_timestamp from topics, posts where topics.topic_ic=posts.topic_id, topics.mod_id=ISA401 , posts.post_timestamp between '2006-08-07' and '2006-08-19' cannot connect
the cannot connect is my error handling message.

guelphdad
08-20-2006, 03:14 PM
then the problem is you aren't connecting to your server or your database, not the query itself.

note you should use
. mysql_error(); appended to your connection call and your database call so that you know the exact error message occuring rather than use your own error message.

husnamina
08-20-2006, 11:59 PM
hi
i can connect to the databse is just my error message is mis leading so i changed it to cannot run query.
i added the mysql_error(); but i think the sql stmnt is wrong.
can i have 2 sql stmnts, though and have a loop to display them separately?

guelphdad
08-21-2006, 12:25 AM
would you like people to guess at the problem? how about you actually post what you are running, including your connection statement. Then show us the actual mysql error that is occuring and not an error message that you may be having the script print out.

GJay
08-21-2006, 07:31 AM
Should the 'where' part of the query not have connecting ANDs or ORs between the parts rather than commas?


where topics.topic_ic=posts.topic_id AND
topics.mod_id=$mod AND
posts.post_timestamp between '$start' and '$end'";

guelphdad
08-21-2006, 01:23 PM
I hate missing the obvious.

Beagle
08-21-2006, 03:13 PM
2 problems:

if this is your query echoed by PHP:


select
topic_title,
topics.mod_id,
topic_creator,
topics.role,
topics.post_timestamp,
post_creator,
posts.role,
posts.post_timestamp
from topics,
posts
where topics.topic_ic=posts.topic_id,
topics.mod_id=ISA401 ,
posts.post_timestamp between '2006-08-07' and '2006-08-19'

The part I put in red is a string, not an int, and therefore needs to be in quotes.

Further, are you sure it's topic_ic and not topic_id?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum