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

Reply
 
Thread Tools Display Modes
  #1  
Old 12-13-2011, 06:31 PM
@ngel @ngel is offline
 
Join Date: Jan 2005
Location: Greece
Posts: 81
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Export Threads

I need to export the posts of the threads of certain forums in csv, maintaining information such as the name of the author, the date of the post etc. To give you an example, what I need is something like this:

____________________

Forum / Subforum
Title of Thread

Author 1
Date
Post 1

Author 2
Date
Post 2

...
____________________

I've tried to export the post table but then posts are not structured under Threads and Forums.
I imagine I should export the posts table along with something else, but I don't know what.
Can you please help me?
Reply With Quote
  #2  
Old 12-13-2011, 11:17 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You could do something like this:

Code:
SELECT  forum.title_clean, thread.title, post.title, post.username, post.dateline, post.pagetext
INTO OUTFILE 'posts.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' 
FROM post
    LEFT JOIN thread ON (post.threadid = thread.threadid)
    LEFT JOIN forum ON (thread.forumid = forum.forumid)
WHERE thread.visible = 1 AND post.visible = 1

I imagine you'll need to tweak some things, but this might be a starting point.
Reply With Quote
  #3  
Old 12-18-2011, 01:29 PM
@ngel @ngel is offline
 
Join Date: Jan 2005
Location: Greece
Posts: 81
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you VERY much for your help.
When I try to execute it though (both on phpmyadmin and in the admin panel) I get

error number: 1045
error desc: Access denied for user

what should I do?
Reply With Quote
  #4  
Old 12-18-2011, 01:50 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think that means that the mysql user you're logged in as doesn't have some permission that's necessary. Maybe it can't create a file, I'm not sure. I don't know much about mysql administration so I don't know what to do about it. If you don't do your own administration then maybe you can ask your host about it.

Maybe you could try specifying a full path instead of just 'posts.csv', if you know the path to your directory on the host. Or maybe if the server is on a different computer you won't be able to do it at all, I'm not sure.

Another possibility would be if you have a database backup you could restore it to another computer (like your local computer, installing mysql first if you don't already have it). Or you could abandon the sql idea and write a php script to do it. Take ou tthe entire "INTO OUTFILE" line and write a loop to get each row and print it to a file.

ETA: looking at this page in the mysql docs: http://dev.mysql.com/doc/refman/5.6/en/select-into.html it says you need FILE privilege and the file would be created on the server's host, so maybe using INTO OUTFILE isn't an option for you.
Reply With Quote
  #5  
Old 12-18-2011, 02:30 PM
@ngel @ngel is offline
 
Join Date: Jan 2005
Location: Greece
Posts: 81
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you very much, so can I just print the results on screen instead of creating a file until I find out the exact query?
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 10:40 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.03875 seconds
  • Memory Usage 2,193KB
  • Queries Executed 13 (?)
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
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete