Mysql join for thread and its replies

cannonball

New Member
Ok, I am willing to create a simple forum for my website. So, let's begin. I guess thread table is going to be smth like this: \[code\]t_id, thread_name, who_created, when_created\[/code\]And replies table is going to be smth like this:\[code\]r_id, t_id, who_wrote, what_wrote, when_wrote\[/code\]And when somebody wants to view thread with replies, he clicks button which moves him to \[code\]index.php?t_id=1\[/code\] or smth like that. \[code\]t_id\[/code\] means threads' table value \[code\]t_id\[/code\]. What join query should I write for showing topic and its replies?\[code\]mysql_query('SELECT * FROM threads AS t INNER JOIN replies AS r ON t.t_id = r.t_id WHERE t.t_id = '.mysql_escape_strings($_GET['t_id']));\[/code\]Is it right? Then how should I pull out all that data? With mysql_fetch_array? Then how? Any suggestions? Maybe better write 2 queries instead of JOIN? Thanks.
 
Back
Top