这个问题显然意味着,我并不是在问SQL
是否加入这里,
我只想合并/合并2个MySQL
结果到PHP
中,但是我尝试使用PHP array_merge()来做到这一点,但没有成功。
$user_paid_query = "SELECT * from users WHERE now_paid!=0 ORDER BY now_paid DESC";
$result_user_paid = $connect->query($user_paid_query);
$users_paid = $result_user_paid->fetch_assoc();
$users_unpaid_query = "SELECT * from users WHERE now_paid=0 ORDER BY id ASC";
$users = array_merge($users_paid, $users_unpaid);
答案 0 :(得分:2)
您可以在MySQL本身(而不是PHP)中使用union
来合并2个SQL结果。
(SELECT * from users WHERE now_paid != 0 ORDER BY now_paid DESC)
UNION
(SELECT * from users WHERE now_paid = 0 ORDER BY id ASC)