我有两个表,我想在其中使用连接两个表进行查询。如果有 pro_pic = '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
未显示空 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 结果总是返回随机行
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句