我有两个查询,我想在单独的 while 循环中得到结果,查询工作正常,但我不知道如何在 while 循环中分离结果。
php
$query = "
SELECT 1 as query, title FROM $tablename WHERE category='category1' LIMIT 10
UNION
SELECT 2 as query, title FROM $tablename WHERE category='category2' LIMIT 10
";
$result = mysqli_query($connection, $query) or trigger_error(mysqli_error($connection), E_USER_ERROR);
while($row = mysqli_fetch_assoc($result[1])){
echo $row['title'].'<br />';
}
while($row = mysqli_fetch_assoc($result[2])){
echo $row['title'].'<br />';
}
请查看并建议任何可能的方法来做到这一点。