[Solved] Unable to query two tables in mysql [closed]


You can make something like this:

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

I can’t really see the names of the tables, so i have just guessed them.

3

solved Unable to query two tables in mysql [closed]