View Full Version : What's wrong with this query?
Deaths
02-19-2005, 06:41 PM
Whats wrong with this query?
SELECT * FROM thread WHERE forum.forumid = 13 ORDER BY ID DESC LIMIT 10
I get this error:
Database error in vBulletin 3.0.6:
Invalid SQL:
SELECT * FROM thread WHERE forum.forumid = 13 ORDER BY ID DESC LIMIT 10
mysql error: Unknown table 'forum' in where clause
mysql error number: 1109
Zachery
02-19-2005, 06:43 PM
SELECT * FROM " . TABLE_PREFIX . "thread WHERE " . TABLE_PREFIX . "forum.forumid = 13 ORDER BY ID DESC LIMIT 10
Marco van Herwaarden
02-19-2005, 06:49 PM
Lol it is not the only prefix Zach :D He refers to the forum table in the where clause, but forum is not used in the FROM clause. Typical copy&paste&edit error.
SELECT * FROM " . TABLE_PREFIX . "thread WHERE forumid = 13 ORDER BY ID DESC LIMIT 10
Deaths
02-19-2005, 07:02 PM
Thanks :).
I don't have time to try this out, but it looks promising.\
Typical copy&paste&edit error.
Yep, so many idea's, so little time... If only I had time to handle every idea with the same time and care...
Zachery
02-19-2005, 10:30 PM
Thanks :).
I don't have time to try this out, but it looks promising.\
Yep, so many idea's, so little time... If only I had time to handle every idea with the same time and care...
I was getting the thing i knew was wrong ;) one at a time ay ? :)
Marco van Herwaarden
02-20-2005, 06:47 AM
ay ay
Deaths
02-20-2005, 07:34 AM
Ya goo' ol' pirate!
Still didn't work :(.
Query:
$getnewposts = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "thread WHERE forumid = 13 ORDER BY ID DESC LIMIT 10");
Error:
Invalid SQL: SELECT * FROM thread WHERE forumid = 13 ORDER BY ID DESC LIMIT 10
mysql error: Unknown column 'ID' in 'order clause'
mysql error number: 1054
Marco van Herwaarden
02-20-2005, 08:13 AM
Hmm ORDER BY threadid or forumid maybe?
Dont know what order you want.
I would say "ORDER BY dateline desc" ;)
But if you want the last posts prefer this one ;)
$getnewposts = $DB_site->query("SELECT p.* FROM " . TABLE_PREFIX . "post as p
LEFT JOIN " . TABLE_PREFIX . "thread as t ON (t.threadid = p.threadid)
WHERE t.forumid = 13 ORDER BY p.dateline DESC LIMIT 10");
Deaths
02-20-2005, 08:54 AM
Ok, now the DB error is gone.
But, with this code:
$getnewposts = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "thread WHERE forumid = 13 ORDER BY dateline desc LIMIT 10
");
$newposts = number_format($getnewposts['count']);
It just returns a "0", even though I'm absolutely sure there's a new post in the forum 13...
Ok I gave the request above as I saw you put LIMIT 10 and didn't put a coherent where clause.
What do you want exactly. A number of posts ?
$getnewposts = $DB_site->query_first("SELECT count(*) as count FROM " . TABLE_PREFIX . "post as p
LEFT JOIN " . TABLE_PREFIX . "thread as t ON (t.threadid = p.threadid)
WHERE t.forumid = 13 ORDER BY p.dateline DESC LIMIT 10");
It's better but, this request will give you the last 10 posts in forumid 13. You must give in the where clause a dateline condition. LIMIT 10 is useless unless you want to display at least 10 last posts and no more
WHERE t.forumid = 13 AND p.dateline > $bbuserinfo[lastvisit]
Deaths
02-20-2005, 09:27 AM
Yes, I want the number of new posts (as a number) from a certain forum (13).
With that code $newposts returns 10, while there are no posts at all...
That what I said ;). How do you want number of newpost to be return has you didn't put any dateline condition in the query ?
Replace this in the query :
WHERE t.forumid = 13
By the last code I gave in post #11 ;)
Deaths
02-20-2005, 04:33 PM
It works now, thanks!
Silly me, I forgot about the dateline condition ^^
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.