我想将 2 个表连接在一起,但无法正常工作。
这些是表格:
线程: id, title
帖子: thread_id,消息
$sql = mysql_query("SELECT threads.id, threads.title
FROM threads
JOIN posts ON posts.thread_id = threads.id
WHERE threads.id = ".intval($_GET['id']));
while ($post = mysql_fetch_assoc($sql))
{
echo $post['title'];
echo $post['message'];
}
它获取标题但未获取消息。我有一个分配给线程。
最佳答案
您没有选择 posts.message。将您的 SQL 更改为此,它可能会起作用。
SELECT threads.id, threads.title, posts.message
FROM threads
JOIN posts ON posts.thread_id = threads.id
WHERE threads.id = $id
关于php - 连接 2 个表时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1161484/