PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old June 25th, 2004, 10:27 AM
ensnare ensnare is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 1 ensnare User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post PHP / MySQL Threaded Discussion: One Query

I'm attempting to create a threaded comment system involving PHP / MySQL. Currently, I have a table called comments which looks like:

Table Comments: (comment_id, comment_root_id, comment_parent_id, text, datetime_created).

Most of the tutorials that I've found online discuss how to thread the results from the database with recursive query calls. This is all to the good; however, with lengthy discussion, this solution becomes slow and unacceptable.

Is there a way to retrieve all the comments from the database in one query (e.g. SELECT * FROM comments WHERE comment_root_id = $id) and then to do the ordering/threading in php with some function?

What would such a function look like?

I found a function online that recurses through an array. Perhaps something like this could be modified to thread the comments?
PHP Code:
[color=#000000]///============
//Sample thread
$thread_info_arr['message_id'] = array(154155156157161163);
$thread_info_arr['reply_id'] = array(0154155154155157);
$thread_info_arr['message_title'] = array('Post 154 (initial post)''Post 155 (reply to post 154)''Post 156 (reply to post 155)''Post 157 (reply to post 154)''Post 161 (reply to post 155)''Post 163 (reply to post 157)');
$thread_info_arr['date_posted'] = array('2004-06-01''2004-06-02''2004-06-03''2004-06-04''2004-06-05''2004-06-06');

$iteration 0;

reord_thread($thread_info_arr['message_id']);

function 
reord_thread(&$data)
{
    global 
$thread_info_arr$iteration;

   if (
is_array($data))
   {
       
array_walk($data'reord_thread');
   }
   else
   {
       echo 
'Date: ' $thread_info_arr['date_posted'][$iteration] . ' Title: ' $thread_info_arr['message_title'][$iteration] . '<br>';
       
$iteration++;
   }
}[/
color
///============ 

Thanks in advance. Any help would be greatly appreciated. Enjoy your day.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP / MySQL Threaded Discussion: One Query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway