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

Reply
 
Thread Tools Display Modes
  #1  
Old 09-05-2005, 07:36 PM
Jorim Jorim is offline
 
Join Date: Jul 2005
Location: Krabbendam (NL)
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Getting the last post of a specific topic

I'm a SQL n00b so I have to ask you guys.

How does the query look, which I need, to get the last post (unparsed) from thread X (vBulletin 3.0.6). I can't figure it out myself :disappointed:

Thanks in advance!

Jorim
Reply With Quote
  #2  
Old 09-06-2005, 12:00 AM
merk merk is offline
 
Join Date: Nov 2001
Location: Canberra, Australia
Posts: 601
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It could be something like the below, but remember that the query could be very specific and this one will only work for one thread and one post. You might need to do 2 queries to actually make it work for any other purpose.

[sql]
SELECT thread.*, post.*
FROM thread
LEFT JOIN post USING (threadid)
WHERE thread.threadid = <THREAD_ID>
ORDER BY post.dateline DESC
LIMIT 1
[/sql]
Reply With Quote
  #3  
Old 09-06-2005, 02:56 AM
AN-net's Avatar
AN-net AN-net is offline
 
Join Date: Dec 2003
Location: AnimationTalk.com
Posts: 2,367
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

better to use a field called lastpost_id in the thread table
Reply With Quote
  #4  
Old 09-06-2005, 04:14 AM
merk merk is offline
 
Join Date: Nov 2001
Location: Canberra, Australia
Posts: 601
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Good point - I didnt even think to look if that existed.

Thanks

[sql]SELECT thread.*, post.* FROM thread LEFT JOIN post ON (thread.lastpostid = post.postid) WHERE thread.threadid=<BLAH>[/sql]
Reply With Quote
  #5  
Old 09-06-2005, 09:03 AM
Jorim Jorim is offline
 
Join Date: Jul 2005
Location: Krabbendam (NL)
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't have that field maybe introduced with 3.0.7 ???

I've got an extra question. I'm only interested in the content of the post, nothing more. How do I change merk's first code to a code that places the content in a variable? I thought i'd know, but my ideas don't work

Thanks for you're help
Reply With Quote
  #6  
Old 09-06-2005, 09:05 AM
merk merk is offline
 
Join Date: Nov 2001
Location: Canberra, Australia
Posts: 601
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The field will exist, it has existed since at least version 2, it might be named slightly differently. I cant remember and cant login to pma to check.

To just get the post content, again, i dont know the exact name of the field, but you would replace

[sql]SELECT thread.*, post.*[/sql]

with

[sql]SELECT post.<FIELDNAME>[/sql]

It will have unprocessed BBCodes in there, you will need to work out how to use the bbcode functions to process them (pretty simple).
Reply With Quote
  #7  
Old 09-06-2005, 10:06 AM
Jorim Jorim is offline
 
Join Date: Jul 2005
Location: Krabbendam (NL)
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$getnews $DB_site->query("SELECT " TABLE_PREFIX "post.pagetext FROM " TABLE_PREFIX "thread LEFT JOIN " TABLE_PREFIX "post ON (" TABLE_PREFIX "thread.lastpost = " TABLE_PREFIX "post.postid) WHERE " TABLE_PREFIX "thread.threadid=7348");
print 
$getnews
Just a test thing , but "Resource id #43" is the output and that's not what i'd like to have

thread.lastpost is wrong or everything is wrong. I've attached a screendumb of the table (thread), but lastpost is likely the one I need...

You're help is again very appreciated...
Attached Images
File Type: gif table.gif (11.3 KB, 0 views)
Reply With Quote
  #8  
Old 09-06-2005, 10:14 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$getnews $DB_site->query("SELECT " TABLE_PREFIX "post.pagetext FROM " TABLE_PREFIX "thread LEFT JOIN " TABLE_PREFIX "post ON (" TABLE_PREFIX "thread.lastpost = " TABLE_PREFIX "post.postid) WHERE " TABLE_PREFIX "thread.threadid=7348");
while (
$news $DB_site->fetch_array($getnews))
{
   
print_r($news);

Reply With Quote
  #9  
Old 09-06-2005, 10:21 AM
Jorim Jorim is offline
 
Join Date: Jul 2005
Location: Krabbendam (NL)
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I need to buy a book...

Thanks Marco

Unfurtunally stays $news empty. Something is still going wrong, thread.lastpost isn't right or...
Reply With Quote
  #10  
Old 09-06-2005, 10:32 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm looking again at your query, i am surprised you don't get an error on it. Try the following:
PHP Code:
$getnews $DB_site->query("
        SELECT pagetext FROM " 
TABLE_PREFIX "post AS post
        LEFT JOIN " 
TABLE_PREFIX "thread AS thread ON (thread.lastpost = post.postid) 
        WHERE thread.threadid=7348"
); 
while (
$news $DB_site->fetch_array($getnews)) 

   
print_r($news); 

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 04:39 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02380 seconds
  • Memory Usage 2,283KB
  • Queries Executed 14 (?)
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
  • (3)bbcode_php
  • (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
  • (1)postbit_attachment
  • (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_postinfo_query
  • fetch_postinfo
  • 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
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete