vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   MySQL all posts by member and post that started corresponding thread (https://vborg.vbsupport.ru/showthread.php?t=174727)

zylstra 03-31-2008 06:08 PM

MySQL all posts by member and post that started corresponding thread
 
What is the MySQL code for selecting all posts by a particular member and the posts that started the corresponding thread for those posts?

Thanks.

Dismounted 04-01-2008 03:34 AM

You want it all lumped into one query, right?

zylstra 04-01-2008 04:58 AM

Yeah, a member of my board would like a file of all his posts and the first post in those threads that he responded to. His posts and their corresponding starting posts will have to be close to each other in the query result, else it won't make sense to him.

zylstra 04-06-2008 10:02 PM

anyone?

Eikinskjaldi 04-08-2008 03:07 AM

What do you want to have happen when there are multiple posts by him in a thread? Lets say there is a thread in which he has replied 100 times. What kind of display are you looking for?

zylstra 04-08-2008 03:36 AM

A list of his posts in a thread followed by (or preceded by) the first post in that thread,
followed by a list of his posts in the next thread that he posted in followed by (or preceded by) the first post in that thread,
followed by a list of his posts in the next thread that he posted in followed by (or preceded by) the first post in that thread,
etc.

Eikinskjaldi 04-08-2008 04:05 AM

It will require the creation of a temporary table, be a big slow process and quite possibly crash your server. You would be better off scripting it in php or any other language that can connect to your db.

This query will return a list of firstpostid, user's posts:

[sql] select concat_ws(',',t.firstpostid, group_concat(p.postid))
from thread t
join post p using (threadid)
where p.userid=your_users_id
group by t.firstpostid[/sql]

example output
Code:

37916,75977,75978,79764,79767,81094,81096
You can then take that list and pass it into a second query
[sql]select p.username, p.pagetext from post where postid in (above_list)[/sql]

Note that group_concat has a character limit, which can be changed if you have the appropriate mysqld permissions.

zylstra 04-08-2008 01:26 PM

Thanks so much Eikinskjaldi! Would it be easier on the server to return this format:

user post
firstpost
user post
firstpost
...

even though the firstpost might be repeated?

Eikinskjaldi 04-10-2008 03:41 AM

Quote:

Originally Posted by zylstra (Post 1485976)
Thanks so much Eikinskjaldi! Would it be easier on the server to return this format:

user post
firstpost
user post
firstpost
...

even though the firstpost might be repeated?

yes it would.

[sql]
select p.username, p.pagetext, q.username, q.pagetext
from post p
joint thread t using (threadid)
join post q on (t.firstpostid=q.postid)
where p.userid=your_users_id
[/sql]

zylstra 04-10-2008 06:56 AM

Great, thank you.


All times are GMT. The time now is 09:44 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.01445 seconds
  • Memory Usage 1,725KB
  • 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
  • (1)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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