我不确定我是否了解您的数据库的结构,但您可以看看这个:
$query = "
SELECT * FROM users u
LEFT JOIN application a
ON u.ID_u = a.ID_u
LEFT JOIN informationuser i
ON a.ID = i.ID
//Here you can specify 'WHERE u.ID_u IN (1,2,3,4)'
GROUP BY i.ID
" ;
$users = array() ; //Create storage for users. Use their ID as indeces
$result = $mysqli->query($query) ;
if ($result && $result->num_rows >= 1){
while ($row = $result->fetch_assoc()){
if (!isset($users[$row['ID_u'])){
$users[$row['ID_u']] = array() ; //Create array for a new user
}
$users[$row['ID_u']][] = array( //Fill array in with data and add it to user.
"email" => $row["email"],
"phone" => $row["phone"]
) ;
}
}
然后,让我们检查用户的数据是否存在ID = 3
(如果 3 是int
):
if (!empty($users[3])){
echo "Yeah, data exists for user with ID 3" ;
}