How to get data from 2 tables? [duplicate]
I am trying to create a website with an existing database. The database has two tables, one of them contain the post info like title, id, content, etc etc, the other table contains the post ID and the post category.
For example: I want to take a post from a specific category.
$sql = 'SELECT * FROM posts WHERE status = "publish" ORDER BY date DESC LIM开发者_如何转开发IT 10';
This is a simple function, can some one help me please how to modify it, to get the category from the other table and the post info from the other table.
SELECT * FROM posts, posts_category WHERE category = 'category'
AND
status = 'publish'
AND
posts_category.post_id = posts.id
ORDER BY date DESC LIMIT 10;
$sql = "SELECT * FROM posts WHERE status = 'publish' AND pid IN (SELECT pid FROM pcategory WHERE ptype='category_name') ORDER BY date DESC LIMIT 10";
精彩评论