I have two queries for which i want to get result in separate while loop, query is working fine but i cant figure out how to get result separated in while loop.
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 />';
}
Please see and suggest any possible way to do this.
1 Answer