Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Mysql线程连接及其回复_Php_Mysql_Forum - Fatal编程技术网

Php Mysql线程连接及其回复

Php Mysql线程连接及其回复,php,mysql,forum,Php,Mysql,Forum,好的,我愿意为我的网站创建一个简单的论坛。那么,让我们开始吧 我猜线程表将是这样的: t_id, thread_name, who_created, when_created r_id, t_id, who_wrote, what_wrote, when_wrote 回复表将是这样的smth: t_id, thread_name, who_created, when_created r_id, t_id, who_wrote, what_wrote, when_wrote 当有人想要查看

好的,我愿意为我的网站创建一个简单的论坛。那么,让我们开始吧 我猜线程表将是这样的:

t_id, thread_name, who_created, when_created
r_id, t_id, who_wrote, what_wrote, when_wrote
回复表将是这样的smth:

t_id, thread_name, who_created, when_created
r_id, t_id, who_wrote, what_wrote, when_wrote
当有人想要查看带有回复的线程时,他单击按钮,将其移动到
index.php?t_id=1
或类似的smth
t\u id
表示线程的表值
t\u id
。我应该编写什么连接查询来显示主题及其回复

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']));

是这样吗?那么我该如何提取所有数据呢?使用mysql\u fetch\u数组?那怎么办?有什么建议吗?也许最好写两个查询而不是JOIN?谢谢。

在这种情况下,不要使用联接,因为它没有任何优势,反而会减慢查询速度。而是执行两个单独的查询:

mysql_query('SELECT *
         FROM threads AS t
         WHERE t.t_id = '.mysql_escape_strings($_GET['t_id']));
以及:


这会快得多。

联接提供的信息与双查询方法完全相同,但由于它会为每个回复复制线程表的列,因此会产生大量(冗余)数据+1.