首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Php mysql使用get输出,我已经提到了

Php mysql使用get输出,我已经提到了
EN

Stack Overflow用户
提问于 2012-10-27 07:22:36
回答 2查看 88关注 0票数 0

可能重复: SQL查询如何从多个表返回数据?

请帮我解决这个问题,我有两个mysql表,

tbl_product

代码语言:javascript
复制
id  name         title  userID
1   Phone        N95       1
2   Tab          Google    1
3   Laptop       Toshiba   1
4   PhoneNext    Nokia     2
5   Mp3 Player   Apple     2
6   Gallexy      Samsung   3
7   Hard         320GB     6

tbl_user

代码语言:javascript
复制
id selName
1  Jhon
2  Khan
3  Mohomad
4  Ann
6  Ricky

我需要像这个输出一样连接这两个表,

代码语言:javascript
复制
Phone N95 (userID = 1)

Tab Google (userID = 1)

Laptop Toshiba (userID = 1)

Jhon (id=1)

代码语言:javascript
复制
PhoneNext Nokia (userID = 2)

Mp3 Player Apple (userID = 2)

Khan (id=2)

代码语言:javascript
复制
Gallexy Samsung (userID = 3)

Mohomad (id=3)

请帮助我,伙计们,谢谢.

代码语言:javascript
复制
I Need to get Like This out put,
<table width="224" border="1"> <tr> <td width="214">Phone N95 (userID = 1)</td> </tr> <tr> <td>Tab Google (userID = 1)</td> </tr> <tr> <td>Laptop Toshiba (userID = 1)</td> </tr> <tr> <td align="right" bgcolor="#FFFF99">Jhon (id=1)</td> </tr> <tr> <td>PhoneNext Nokia (userID = 2)</td> </tr> <tr> <td>Mp3 Player Apple (userID = 2)</td> </tr> <tr> <td align="right" bgcolor="#FFFF99">Khan (id=2)</td> </tr> </table> 
EN

回答 2

Stack Overflow用户

发布于 2012-10-27 07:34:08

你就不能用这样的东西吗?

代码语言:javascript
复制
Select title,userID from tbl_product 
where tbl_product.userID = tbl_user.id 
group by userID
票数 0
EN

Stack Overflow用户

发布于 2012-10-27 07:52:20

代码语言:javascript
复制
SELECT tbl_product.userID, tbl_product.name, tbl_product.title, tbl_user.selName 
FROM tbl_product
LEFT JOIN tbl_user ON tbl_product.userID = tbl_user.id
GROUP BY tbl_product.userID

我建议开始阅读有关MySQL的基础知识。

MySQL DOC

MySQL选择

MySQL连接

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13098150

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档