-5

如何显示所有 tutorial_post 和发布帖子的用户的用户名...我想看看 sql 语句的样子

在此处输入图像描述 在此处输入图像描述

4

1 回答 1

0

你可以做这样的事情:

$postID = 1;//Post id we want to get from the database
$getPost = $connection->query("SELECT * FROM posts WHERE post_id='$postID'");//Get the post by the id
$post = $getPost->fetch_assoc();//Fetch the result to an array
$getUser = $connection->query("SELECT username FROM users WHERE user_id=".$post['id']);//Get the username by using the id we got from the $post['user_id']
$user = $getUser->fetch_assoc();//Fetch the second result to an array

//Print everything
echo "Title:".$post['title']."<br/>";
echo "Username:".$user['username']."<br/>";
echo "Body:".$post['body'];

我真的看不到表的名称,所以我只是猜到了。

于 2013-06-13T19:34:22.143 回答