mysqli_multi_query() 重复获取 null

mysqli_multi_query() repeats the fetched with null

我正在尝试使用 mysqli_multi_query() 从多个表中获取所有知道 "Photoshop" 的用户及其所有详细信息。我也得到了结果,但是也有一些不速之客以及正确的结果是空的。他们为什么会在这里?

代码和输出如下:

<?php
    $sql = "SELECT user_id FROM ts_users_skills WHERE skillsTeach='Photoshop'";
    if($res = mysqli_query($conn,$sql)) {
        while ($id=mysqli_fetch_array($res)) {
                $id=$id['user_id'];
                // echo($id);
                $get_teachers_details="SELECT * FROM ts_students_log WHERE user_id='$id';";
                $get_teachers_details.="SELECT * FROM ts_students_info WHERE user_id='$id';";
       if (mysqli_multi_query($conn,$get_teachers_details))
        {
            do
                {
    // Store first result set
                if ($mul_res=mysqli_store_result($conn)) {
                  // Fetch one and one row
                  while ($row=mysqli_fetch_assoc($mul_res))
                    {
                    // printf("%s\n",$row['mobile']);
                         // print_r($row);
                        echo "Id: " . $row['user_id']. " Mobile: " . $row['mobile']. "Email:-" . $row['email'] . "Name:-" .$row['name'] . "<br/>";      
                    }           
                  //            Free result set         
                  mysqli_free_result($mul_res);         
                  }
                }
    while (mysqli_next_result($conn));
}
}
}
?>

输出:

     Id: 3 Mobile: 7895447755Email:-aditya@chutiya.comName:-
     Id: 3 Mobile: Email:-Name:-Aditya Porwal
     Id: 4 Mobile: 9300010740Email:-rishabhgaandu@gmail.comName:-
     Id: 4 Mobile: Email:-Name:-Rishabh Agrawal

合并您的查询以获得一个您可以随意排序的结果集:

SELECT 
    a.`user_id`,
    b.*,
    c.*
FROM ts_users_skills a
LEFT JOIN ts_students_log b
    ON a.`user_id` = b.`user_id`
LEFT JOIN ts_students_info c
    ON a.`user_id` = c.`user_id`
WHERE a.`skillsTeach` = 'Photoshop'
ORDER BY a.`user_id`;

我使用了 LEFT JOINs,但是如果所有用户在 ts_students_info 和 ts_students_info 中都有行,您可以将它们更改为仅 加入s.

编辑

要在下面的评论中回答您的问题,select 多项技能,请将 where 子句更改为类似以下内容:

WHERE  a.`skillsTeach` in ('Photoshop','Video Editing','Web Design')

WHERE  a.`skillsTeach` = 'Photoshop'
    OR a.`skillsTeach` = 'Video Editing'
    OR a.`skillsTeach` = 'Web Design'