vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   How can i get the first post only? (https://vborg.vbsupport.ru/showthread.php?t=184174)

vietdjclub 07-02-2008 12:54 PM

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

Opserty 07-02-2008 02:32 PM

[SQL]
SELECT *
FROM thread
LEFT JOIN post ON ( post.postid = thread.firstpostid )
WHERE thread.threadid = AAA
[/SQL]
(Where AAA is the thread id)

vietdjclub 07-03-2008 12:06 AM

thank Opserty

Dismounted 07-03-2008 05:36 AM

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]

Paul M 07-03-2008 01:55 PM

I hate it when people use single letters in sql. :)

Dismounted 07-03-2008 02:14 PM

[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? :p

Opserty 07-03-2008 03:53 PM

You don't need the "AS thread" or "AS post" if they are the same as the table names no? :p

Blindspot 07-03-2008 10:35 PM

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']); 


vietdjclub 07-03-2008 11:31 PM

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,

vietdjclub 07-04-2008 03:19 AM

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,

Dismounted 07-04-2008 03:55 AM

What are you trying to do there? Why are you assigning the thread id to pagetext? Please explain what you want to do.

vietdjclub 07-04-2008 04:34 AM

Quote:

Originally Posted by Dismounted (Post 1566438)
What are you trying to do there? Why are you assigning the thread id to pagetext? Please explain what you want to do.

thank for your reply.

my plan for the mod:

step 1: run query to get 10 threadid from thread table
step 2: auto create 1 new thread on the special forum, with 10 threadid that i got from step 1

ex:

step 1: after query i got threadid = 1,2,3,4,5,6,7,8,9,10
step 2: one new thread auto open on the special forum = 3
step 3: then put 1,2,3,4,5,6,7,8,9,10 on the new thread on step 2


please help me. thank again

Blindspot 07-04-2008 05:07 AM

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']); 


vietdjclub 07-04-2008 09:31 AM

finally i found how to do it. thank for support

Opserty 07-04-2008 09:45 AM

Quote:

Originally Posted by Blindspot (Post 1566503)
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']); 


Using that method you'd be using two queries, when you can cover it in a single query with a JOIN.

vietdjclub 07-04-2008 02:20 PM

exactly as Opserty said. I use JOIN

vietdjclub 07-08-2008 08:23 AM

1 Attachment(s)
Thank friends for helping me . i just finished my mod on yesterday
mod: Auto Top 10 Threads - Auto run very month

some pics for the mod (setting & Result)


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

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.01640 seconds
  • Memory Usage 1,766KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (6)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (17)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete