PDA

View Full Version : Question about query syntax


Robert Basil
04-14-2005, 08:03 PM
I'm trying to pull the last 3 posts from a few forums and then sort the by the forum's name. Here is what I have so far:

SELECT t.threadid, t.title, t.firstpostid, t.lastpost, f.title as forumtitle, t.replycount, t.postusername, t.postuserid, t.lastposter, t.dateline, t.views, p.pagetext, t.iconid, t.forumid
FROM thread t
LEFT JOIN post p ON p.postid = t.firstpostid
LEFT JOIN forum f ON f.forumid = t.forumid
WHERE t.forumid
IN ( 19, 116 )
AND t.open = '1'
AND t.visible = '1'
ORDER BY forumtitle DESC
LIMIT 0 , 3

The code above only pull 3 total posts from the forums, any ideas on how to pull the last 3 posts from each forum?

Thanks in advance!

tnguy3n
04-15-2005, 12:29 AM
Assuming you'd put this code bit in forumdisplay.php file.


SELECT forum.forumid, forum.title AS forumtitle, thread.*, post.*
FROM " . TABLE_PREFIX . " thread AS thread
LEFT JOIN " . TABLE_PREFIX . "forum AS forum ON(forum.forumid = thread.forumid)
LEFT JOIN " . TABLE_PREFIX . "post AS post ON(thread.lastpost = post.postid)
WHERE thread.forumid = '" . intval($forumid) . "'
AND thread.visible = 1
ORDER BY forumtitle
LIMIT 0, 3


I'm trying to pull the last 3 posts from a few forums and then sort the by the forum's name. Here is what I have so far:

SELECT t.threadid, t.title, t.firstpostid, t.lastpost, f.title as forumtitle, t.replycount, t.postusername, t.postuserid, t.lastposter, t.dateline, t.views, p.pagetext, t.iconid, t.forumid
FROM thread t
LEFT JOIN post p ON p.postid = t.firstpostid
LEFT JOIN forum f ON f.forumid = t.forumid
WHERE t.forumid
IN ( 19, 116 )
AND t.open = '1'
AND t.visible = '1'
ORDER BY forumtitle DESC
LIMIT 0 , 3

The code above only pull 3 total posts from the forums, any ideas on how to pull the last 3 posts from each forum?

Thanks in advance!

Robert Basil
04-15-2005, 10:50 PM
Assuming you'd put this code bit in forumdisplay.php file.


SELECT forum.forumid, forum.title AS forumtitle, thread.*, post.*
FROM " . TABLE_PREFIX . " thread AS thread
LEFT JOIN " . TABLE_PREFIX . "forum AS forum ON(forum.forumid = thread.forumid)
LEFT JOIN " . TABLE_PREFIX . "post AS post ON(thread.lastpost = post.postid)
WHERE thread.forumid = '" . intval($forumid) . "'
AND thread.visible = 1
ORDER BY forumtitle
LIMIT 0, 3


The code above will not work.

I'm not putting it into the forumdisplay.php file, I'm putting it into the query box with Logician's hack:

WebTemplates 3.x: VB Integrated Content Management System

Link to my question (and some ideas I have tried) in that thread.

https://vborg.vbsupport.ru/showthread.php?p=641267#post641267

I've also tried using the ORDER BY query option but no luck.

Thanks for the try anyway. :)

Any other ideas?