Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-05-2009, 09:09 PM
zeroality zeroality is offline
 
Join Date: Jul 2006
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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";
It returns 'Array' where the latest posts should show up.

http://www.pkmndex.com/posts
Reply With Quote
  #2  
Old 07-05-2009, 10:57 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 07-07-2009, 12:47 AM
zeroality zeroality is offline
 
Join Date: Jul 2006
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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";
http://www.pkmndex.com/posts
Reply With Quote
  #4  
Old 07-07-2009, 04:59 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Too many queries there...
PHP Code:
$lastpost_titles = array();
$lastpostdata $db->query_read("
    SELECT thread.threadid, thread.title
    FROM " 
TABLE_PREFIX "thread AS thread
    LEFT JOIN " 
TABLE_PREFIX "post AS post ON(thread.lastpostid = post.postid)
    WHERE thread.forumid <> 31
    ORDER BY thread.lastpost DESC
    LIMIT 4
"
);

while (
$post $db->fetch_array($lastpostdata))
{
    
$lastpost_titles[] = '<a href="forums/showthread.php?t=' $post['threadid'] . '">' $post['title'] . '</a>';
}

echo 
implode('<br />'$lastpost_titles); 
Reply With Quote
  #5  
Old 07-07-2009, 06:49 PM
zeroality zeroality is offline
 
Join Date: Jul 2006
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #6  
Old 07-07-2009, 06:54 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm pretty sure it would be:
PHP Code:
WHERE thread.forumid NOT IN ('31','32'
Reply With Quote
  #7  
Old 07-08-2009, 01:31 AM
zeroality zeroality is offline
 
Join Date: Jul 2006
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yup that works. Thanks so much guys.
Reply With Quote
  #8  
Old 07-28-2009, 06:49 PM
el diablo el diablo is offline
 
Join Date: Apr 2002
Location: Cali, baby!
Posts: 62
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
$lastpost_titles = array();
$lastpostdata $db->query_read("
    SELECT thread.threadid, thread.title
    FROM " 
TABLE_PREFIX "thread AS thread
    LEFT JOIN " 
TABLE_PREFIX "post AS post ON(thread.lastpostid = post.postid)
    WHERE thread.forumid <> 31
    ORDER BY thread.lastpost DESC
    LIMIT 4
"
);

while (
$post $db->fetch_array($lastpostdata))
{
    
$lastpost_titles[] = '<a href="forums/showthread.php?t=' $post['threadid'] . '">' $post['title'] . '</a>';
}

echo 
implode('<br />'$lastpost_titles); 
I've tried a million different things, but still get the same warnings/errors.

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!
Reply With Quote
  #9  
Old 07-28-2009, 07:35 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #10  
Old 07-28-2009, 08:22 PM
el diablo el diablo is offline
 
Join Date: Apr 2002
Location: Cali, baby!
Posts: 62
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
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?
Hey Lynne,

Thanks for the reply.

Well, I actually changed that part of the code to:

PHP Code:
        WHERE thread.forumid NOT IN ('3'
I should have updated that part.

As for the rest of the page, it's all HTML, except for the following:

PHP Code:
<?php require_once('/home/******/public_html/i/include/functions.php');
require_once(
'/home/******/public_html/i/forums/includes/functions_misc.php'); 
require_once(
'/home/******/public_html/i/forums/includes/config.php');
?>
I was trying to create it as it's own function within functions.php (my own file), but then added a new function to functions_misc.php ... either way, no dice.

Maybe I'm overlooking something super simple? Not used to vBulletin these days, so who knows...

Thanks for the reply!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:21 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07280 seconds
  • Memory Usage 2,277KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (5)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete