Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 07-02-2008, 01:54 PM
vietdjclub vietdjclub is offline
 
Join Date: Oct 2007
Posts: 117
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How can i get the first post only?

somebody know the way to get only first post ,

ex: i have the topic with 20 reply on it.

xxx (owner posted)
x1
x2
x3
...
x20

now i want to write a query to get only xxx (owner posted)
how can i do it
Thank for reading my question
Reply With Quote
  #2  
Old 07-02-2008, 03:32 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

[SQL]
SELECT *
FROM thread
LEFT JOIN post ON ( post.postid = thread.firstpostid )
WHERE thread.threadid = AAA
[/SQL]
(Where AAA is the thread id)
Reply With Quote
  #3  
Old 07-03-2008, 01:06 AM
vietdjclub vietdjclub is offline
 
Join Date: Oct 2007
Posts: 117
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thank Opserty
Reply With Quote
  #4  
Old 07-03-2008, 06:36 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You may want to just grab the post's info, instead of including thread data, to save on memory.
[sql]SELECT p.*
FROM thread AS t
LEFT JOIN post AS p ON (p.postid = t.firstpostid)
WHERE t.threadid = X[/sql]
Reply With Quote
  #5  
Old 07-03-2008, 02:55 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I hate it when people use single letters in sql.
Reply With Quote
  #6  
Old 07-03-2008, 03:14 PM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

[sql]SELECT post.*
FROM thread AS thread
LEFT JOIN post AS post ON (post.postid = thread.firstpostid)
WHERE thread.threadid = X[/sql]
Happy now, Paul?
Reply With Quote
  #7  
Old 07-03-2008, 04:53 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You don't need the "AS thread" or "AS post" if they are the same as the table names no?
Reply With Quote
  #8  
Old 07-03-2008, 11:35 PM
Blindspot Blindspot is offline
 
Join Date: Oct 2004
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

even easier
PHP Code:
$postinfo fetch_postinfo($thread['firstpostid']); 
and if you dont have $thread

PHP Code:
$threadinfofetch_postinfo($threadid);
$postinfo fetch_postinfo($threadinfo['firstpostid']); 
Reply With Quote
  #9  
Old 07-04-2008, 12:31 AM
vietdjclub vietdjclub is offline
 
Join Date: Oct 2007
Posts: 117
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

wow it's great for coder. big thank all

--------------- Added [DATE]1215142664[/DATE] at [TIME]1215142664[/TIME] ---------------

thank for first question. now i got trouble with query

my query:
Code:
$x = $vbulletin->db->query_read("
			SELECT * FROM " . TABLE_PREFIX . "thread as t 
			INNER JOIN " . TABLE_PREFIX . "post as p ON (t.threadid = p.threadid)			
			WHERE forumid IN(xx) ORDER BY p.post_thanks_amount DESC LIMIT 0 , 5");

while ($xxx = $vbulletin->db->fetch_array($x))
		{				
			$mymessage = $xxx['threadid'];					 	
			$threaddm->do_set('pagetext', $mymessage);
		}
more code....

the thread auto create perfectly with all infomation but 'pagetext' can not get anything from my query, it's empty.

i want to ask who can help me: how can i get 5 threadid and put it on 'pagetext'

it's mean 1 new thread with 5 threadid (i got from above query) on its

best regard,
Reply With Quote
  #10  
Old 07-04-2008, 04:19 AM
vietdjclub vietdjclub is offline
 
Join Date: Oct 2007
Posts: 117
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

please help me with code

my query:
Code:
$x = $vbulletin->db->query_read("
			SELECT * FROM " . TABLE_PREFIX . "thread as t 
			INNER JOIN " . TABLE_PREFIX . "post as p ON (t.threadid = p.threadid)			
			WHERE forumid IN(xx) ORDER BY p.post_thanks_amount DESC LIMIT 0 , 5");

while ($xxx = $vbulletin->db->fetch_array($x))
		{				
			$mymessage = $xxx['threadid'];					 	
			$threaddm->do_set('pagetext', $mymessage);
		}

               $threaddm->do_set('forumid', $to_forum_1);	
		$threaddm->do_set('postuserid', $postuserid);
		$threaddm->do_set('userid', $postuserid);
		$threaddm->do_set('username', $postusername);		
    		$threaddm->do_set('title', $title);
		$threaddm->do_set('allowsmilie', $allowsmilie);
		$threaddm->do_set('visible', $visible);
                $tid = $threaddm->save();
the thread auto create perfectly with all infomation but 'pagetext' can not get anything from my query, it's empty.

i want to ask who can help me: how can i get 5 threadid and put it on 'pagetext'

it's mean 1 new thread with 5 threadid (i got from above query) on its

best regard,
Reply With Quote
Reply

Thread Tools
Display Modes

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 11:09 PM.


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.08274 seconds
  • Memory Usage 2,265KB
  • Queries Executed 12 (?)
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
  • (2)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
  • (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