Log in

View Full Version : SQL problems



hmsnacker123
07-29-2008, 03:19 AM
Hi, i am currently writing a php script that use's mysql, i'll cut straight to the point - heres the sql code:

SELECT f.id as id, f.forum_name as forum,
f.forum_desc as description,
count(forum_id) as threads, u.name as mod
FROM forum_forum f
LEFT JOIN forum_posts p
ON f.id = p.forum_id
AND p.topic_id=0
LEFT JOIN forum_users u
ON f.forum_moderator = u.id
GROUP BY f.id
And when it try to load the page that its on, i get this:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mod FROM forum_forum f LEFT JOIN forum_posts p ON f.id = p.forum_id ' at line 3

If anyone can spot any errors in the code / or correct it, it will be greatly appreciated.

BliarOut
08-01-2008, 12:44 PM
I think you need a comma here...

FROM forum_forum, f

hmsnacker123
08-01-2008, 03:01 PM
Hey, thanks for the idea but it doesent work, umm anyone else have any ideas?

tfit
08-01-2008, 07:58 PM
where is your where clause?

hmsnacker123
08-01-2008, 10:58 PM
there does'nt have to be one does there?

tfit
08-03-2008, 06:11 AM
No, not necessarily, but does join work with and or does where work with and?
But your string is very confusing: u isn't included in from and join works on tables.
So what happens if you replace:

FROM forum_forum f with
FROM forum_forum, f, u

allahverdi
08-03-2008, 01:11 PM
there is an operator mod() in MySQL. (Checked it in mysql documentation)

I think problem is in it.


u.name as mod

tfit
08-03-2008, 03:49 PM
there is an operator mod() in MySQL. (Checked it in mysql documentation)

I think problem is in it.


u.name as mod


I think the solutions as well!

Knowledge sometimes is in small things

allahverdi
08-03-2008, 05:21 PM
yay :) solved one more problem ))

P.S. hmsnacker123, waiting your reply :D