Php 从3个表中查询数据
我这里有三张桌子:Php 从3个表中查询数据,php,mysql,Php,Mysql,我这里有三张桌子: + _news : id, title, url, image // This table contents all data of news. + _block : bid, id // This table content id of news and bid + _block_cate : bid, title, url // This table content type of news : PHP, SQL, HTML 每个表的数据如下所示: + _news
+ _news : id, title, url, image // This table contents all data of news.
+ _block : bid, id // This table content id of news and bid
+ _block_cate : bid, title, url // This table content type of news : PHP, SQL, HTML
每个表的数据如下所示:
+ _news : id, title, url, image
1 title1 url1 image1
2 title2 url2 image2
+ _block : bid, id // id here is if of news.
1 1
2 1
1 3
+ _block_cate : bid, title, url // This table contents data of each type.
1 PHP php
2 SQL SQL
3 HTML html
我试图在我的主页上打印这样的结果:
+ _news : id, title, url, image
1 title1 url1 image1
2 title2 url2 image2
+ _block : bid, id // id here is if of news.
1 1
2 1
1 3
+ _block_cate : bid, title, url // This table contents data of each type.
1 PHP php
2 SQL SQL
3 HTML html
- 新闻(1)-标题
- 类型:PHP、SQL
- 新闻(2)-标题2
- 类型:HTML
我希望有人能给我一个建议。从你的问题中我不清楚你需要什么。我想你需要这样的建议
select NW.title,* from _news NW
left join _block BK ON NW.id=BK.id
left join _block_cate BC ON BK.bid = BC.bid
这应该对你有用