[英]how to Join two mysql tables in php
我有两个表,我想用连接两个表查询。 如果有pro_pic ='NULL'而不是我想要的结果而没有null pro_pic。
这是表:
用户信息
ID user_id full_name country
--------------------------------------
1 Star01 Sagor Us
2 Star02 Rofiq India
3 Star03 Karim Aus
pro_pic
ID user_id pro_pic
---------------------------------
1 Star01 14523.png
2 Star02 NULL
3 Star03 554513.png
所以我想结果像
ID user_id full_name country pro_pic
------------------------------------------------------------------
1 Star01 Sagor Us 14523.png
3 Star03 Karim Aus 554513.png
null pro_pic字段未显示。
这是我的查询,但我没有得到结果:'(
<?php
$stmt1 = mysqli_query($con,"SELECT ui.user_id, pp.pro_pic, pp.user_id,
ui.full_name, ui.country
FROM user_info
INNER JOIN pro_pic ON ui.user_id=pp.user_id where ui.show_hide_profile != '1' and pp.pro_pic != '' limit $current, $limit");
while($user_info = mysqli_fetch_array($stmt1)){
echo $user_id_view = $user_info['user_id'];
echo $full_name = $user_info['full_name'];
echo $country = $user_info['country'];
echo $pro_pic = $user_info['pro_pic'];
}
?>
感谢所有人,请帮助我
尝试这个
$stmt1 = mysqli_query($con,"SELECT ui.user_id, pp.pro_pic, pp.user_id, ui.full_name, ui.country
FROM user_info ui
INNER JOIN pro_pic pp ON ui.user_id=pp.user_id where pp.pro_pic IS NOT NULL
ORDER BY ui.user_id limit $current, $limit");
编辑:添加order by子句请注意,每当使用limit子句时,您应该使用order by子句,因为如果您不使用order by子句,MySQL结果总是返回随机行
使用此查询
$sql = "SELECT * FROM citys LEFT JOIN comments ON comments.city=citys.city WHERE citys.id=$id";
以下是代码的链接:
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.