Jump to content

Second Unique ID in table


arpowers

Recommended Posts

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?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/73924-second-unique-id-in-table/
Share on other sites

when I did this I used three fields to track messages.

 

A unique ID

 

A root ID

 

A parent ID

 

unique is self explanatory..

 

Root was either 0 for a starting thread or the unique id of the starting thread..

 

Parent the id of the message the current is replying to.

 

This allowed listing of post (SELECT... where root = 0)

 

selecting all post in one thread (SELECT...where root = 'x' OR unique = 'x' ORDER BY root ASC)

 

I then placed this data into an array which had a recursive loop to list the nodes...

 

JOB Done

Fantastic solution Toon~ !  I think you may have solved my problem...

 

So to set the root you:

set root to default to 0

and set root to the unique id of the true root for replies?

 

I didn't think of the parent_id thing, i was planning on sorting by the timestamp.. 

is there a problem with that approach?

thanks again!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.