The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
specific mySQL query question
I am trying to get latest posts to display on a non vB page and I think I am close to having it work.
Code:
$lpost = $db->query_first('SELECT b.title,a.threadid,a.username,a.userid,a.dateline FROM ' . TABLE_PREFIX . 'post a,thread b WHERE a.threadid = b.threadid AND b.forumid NOT IN (31) ORDER BY a.dateline DESC LIMIT 0 , 5'); echo "test<br>"; echo "$lpost"; http://www.pkmndex.com/posts |
#2
|
||||
|
||||
It returns 'array' because it is an array. The variables would be $lpost['title'] and $lpost['threadid'] etc. And usually you would not use echo.
|
#3
|
|||
|
|||
Ah, great! That worked. Now I have another problem. It pulls the latest posts, even if they are in the same thread. So say the latest 4 forum posts are in the same thread, it pulls that - repeating the threads. How do I make it pull different threads that the latest posts have been in without repeating the threads? I hope that's clear enough for you to understand.
Here's the code: Code:
$lpost = $db->query_first('SELECT b.title,a.threadid,a.username,a.userid,a.dateline FROM ' . TABLE_PREFIX . 'post a,thread b WHERE a.threadid = b.threadid AND b.forumid NOT IN (31) ORDER BY a.dateline DESC LIMIT 0 , 1'); $lpost_title = "<a href=\"forums/showthread.php?t=$lpost[threadid]\">$lpost[title]</a>"; $lpost2 = $db->query_first('SELECT b.title,a.threadid,a.username,a.userid,a.dateline FROM ' . TABLE_PREFIX . 'post a,thread b WHERE a.threadid = b.threadid AND b.forumid NOT IN (31) ORDER BY a.dateline DESC LIMIT 1 , 1'); $lpost2_title = "<a href=\"forums/showthread.php?t=$lpost2[threadid]\">$lpost2[title]</a>"; $lpost3 = $db->query_first('SELECT b.title,a.threadid,a.username,a.userid,a.dateline FROM ' . TABLE_PREFIX . 'post a,thread b WHERE a.threadid = b.threadid AND b.forumid NOT IN (31) ORDER BY a.dateline DESC LIMIT 2 , 1'); $lpost3_title = "<a href=\"forums/showthread.php?t=$lpost3[threadid]\">$lpost3[title]</a>"; $lpost4 = $db->query_first('SELECT b.title,a.threadid,a.username,a.userid,a.dateline FROM ' . TABLE_PREFIX . 'post a,thread b WHERE a.threadid = b.threadid AND b.forumid NOT IN (31) ORDER BY a.dateline DESC LIMIT 3 , 1'); $lpost4_title = "<a href=\"forums/showthread.php?t=$lpost4[threadid]\">$lpost4[title]</a>"; $lpost5 = $db->query_first('SELECT b.title,a.threadid,a.username,a.userid,a.dateline FROM ' . TABLE_PREFIX . 'post a,thread b WHERE a.threadid = b.threadid AND b.forumid NOT IN (31) ORDER BY a.dateline DESC LIMIT 4 , 1'); $lpost5_title = "<a href=\"forums/showthread.php?t=$lpost5[threadid]\">$lpost5[title]</a>"; echo "$lpost_title<br>"; echo "$lpost2_title<br>"; echo "$lpost3_title<br>"; echo "$lpost4_title<br>"; echo "$lpost5_title"; |
#4
|
||||
|
||||
Too many queries there...
PHP Code:
|
#5
|
|||
|
|||
OK, that worked great. How do I include more forums that I don't want showing up in the latest posts? I'm assuming that WHERE thread.forumid <> 31 will only work if it's the one forum? <> being less/greater than? So if it were WHERE thread.forumid <> 31,32, it wouldn't work, right?
Thanks for the excellent code, this should be the last thing I need. |
#6
|
||||
|
||||
I'm pretty sure it would be:
PHP Code:
|
#7
|
|||
|
|||
Yup that works. Thanks so much guys.
|
#8
|
|||
|
|||
hey guys, I know this isn't my thread, but I actually wanted to do this same thing on my site, but can't seem to pull it off without warnings. And, when I take out the warnings, it's still not pulling any data out, which was pretty obvious after reading the warnings ;-)
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/****/public_html/i/include/functions.php on line 53 I'm using the same code as above: PHP Code:
Basically, I'm trying to pull the info from the forums onto the front page of my site, which is a static php page. Any help would be much appreciated! |
#9
|
||||
|
||||
The code posted was to be part of another page they made. What do you have in the rest of the page? And you really want them pulled from the same forumid?
|
#10
|
|||
|
|||
Quote:
Thanks for the reply. Well, I actually changed that part of the code to: PHP Code:
As for the rest of the page, it's all HTML, except for the following: PHP Code:
Maybe I'm overlooking something super simple? Not used to vBulletin these days, so who knows... Thanks for the reply! |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|