Unique id + semi unique thread_id column.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
arpowers
Forum Commoner
Posts: 76
Joined: Sun Oct 14, 2007 10:05 pm
Location: san diego, ca

Unique id + semi unique thread_id column.

Post by arpowers »

Hi!

I'm trying to create a messaging system for a project I'm working on.
Theoretically I only need one table to do this, but I do need a unique auto increment primary key 'id' and a thread_id column.

The thread_id column will contain a unique value for new messages, and will contain referential values for thread replies (children)..
What is the best way of accomplishing this or should I just create a thread table with just one column?

So to recap I need standard id, plus a thread_id that will be unique for new threads and referential for replies.

Thanks!
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Storing trees in SQL is certainly cool! In this solution you can retrieve an entire thread in just one query! That's hawt.

This is the original article that started the whole thing off (1996):
http://www.dbmsmag.com/9603d06.html

Rails implements it a few ways:
http://wiki.rubyonrails.org/rails/pages/ActsAsNestedSet (comes with Rails)
http://wiki.rubyonrails.org/rails/pages/BetterNestedSet (a plugin)

Here's the overview of what you want:
http://api.rubyonrails.org/classes/Acti ... thods.html

And here's the source code (in Ruby, but you could learn a lot from this, then write it in PHP)
http://api.rubyonrails.org/classes/Acti ... thods.html

There may already be a PHP version of this, but I don't know it.
Post Reply