如果你看到我的输出在第一个用户asad ali 2行跟随和图像路径之间的差距,为什么其他用户没有任何差距为什么?我想在第一个用户中删除这个差距,感谢您的帮助 只有php编码我正在使用sql查询左表连接 在图像表中当用户上传图像数据时保存在数据库图像中,用户ID为&图像path.if一个用户上传不同的图像然后用户ID重复,所以我想只打印一次用户ID和相同user.same的所有相关图像,如果名称在表中重复,那么我想在输出中打印唯一
我的编码是
<?php
$conn = mysqli_connect("localhost","root","","discover");
if(isset($_REQUEST['user_id']) && isset($_REQUEST['session_id'])){
$user_id=$_REQUEST['user_id'];
$session_id=$_REQUEST['session_id'];
$sql="SELECT * FROM `users` where user_id='$user_id' AND session_id='$session_id'";
$result=mysqli_query($conn,$sql);
if($result->num_rows>0)
{
$sqlb="SELECT * FROM `users` LEFT JOIN `followers` ON users.user_id=followers.user_id LEFT JOIN `image` ON users.user_id=image.user_id order by users.user_id asc";
$resultb=mysqli_query($conn,$sqlb);
if($resultb->num_rows>0)
{
$i=0;
$user_id=array();
$result=array();
// $user_name=array();
// $user_pic_path=array();
while ($rowb = $resultb->fetch_assoc())
{
var_dump($rowb);
$userid = $rowb['user_id'];
$user_name = $rowb['fast_name']." ".$rowb['last_name'];
$user_pic_path=$rowb['user_pic_path'];
$user_follow=$rowb['follower_id'];
if($user_follow == $user_id)
{
$user_followi = TRUE;
}
elseif($user_follow !== $user_id)
{
$user_followi = FALSE;
}
if(!isset($result[$userid]))
{
$result[] = array('user_name'=>$user_name,'user_profile_pic'=>$user_pic_path,'follow'=>$user_followi);
}
$result[$userid]['image_path'][] = $rowb['image_path'];
}
$response['session']=TRUE;
$response['status']=TRUE;
$response['msg']="user data find successfully";
$response['user_detail']=$result;
echo json_encode($response);
}
}
else
{
$response['session']=TRUE;
$response['status']=FALSE;
$response['msg']="wrong data enter";
echo json_encode($response);
}
}
else
{
$response['session']=FALSE;
$response['status']=FALSE;
$response['msg']="user does not exists";
echo json_encode($response);
}
?>
我的输出是
// 20180103125211
// http://localhost/1111.php?user_id=2&session_id=953455543
{
"session": true,
"status": true,
"msg": "user data find successfully",
"user_detail": [
{
"user_name": "asad ali",
"user_profile_pic": "localhost/uploads/image/9152108abc",
"follow": false
},
{
"image_path": [
"localhost/uploads/image/7947861Discover All In One.png"
]
},
{
"user_name": "asim kabeer",
"user_profile_pic": "localhost/uploads/image/1952108xyz",
"follow": false,
"image_path": [
"localhost/uploads/image/2152108Mart Zone - All in one.png",
"localhost/uploads/image/1787860Discover All In One.png"
]
},
{
"user_name": "saad hussain",
"user_profile_pic": "localhost/uploads/image/5152108ytp",
"follow": false,
"image_path": [
"localhost/uploads/image/6547860Discover All In One.png",
"localhost/uploads/image/1474008Mart Zone - All in one.png"
]
},
{
"user_name": "nazeer hussain",
"user_profile_pic": "localhost/uploads/image/7352108trp",
"follow": false,
"image_path": [
"localhost/uploads/image/1547860Discover All In One.png"
]
},
{
"user_name": "asad zahoor",
"user_profile_pic": "localhost/images/ftftft",
"follow": false,
"image_path": [
"localhost/uploads/image/1081552Mart Zone - All in one.png"
]
},
{
"user_name": "ali hussain",
"user_profile_pic": "localhost/images/sduhsud.png",
"follow": false,
"image_path": [
"localhost/uploads/image/5547860Discover All In One.png"
]
}
]
}