I have the same query filtered by two different conditions and want to check if it returns results, in the example below I write two queries and use the RecordCount function, but is there a more efficient way to do this with just one query ?
$query1 = "SELECT col1, col2 FROM table WHERE catid = 1";
$result1 = $db->execute($query1);
$totalRows_result1 = $result1->RecordCount();
$query2 = "SELECT col1, col2 FROM table WHERE catid = 2";
$result2 = $db->execute($query2);
$totalRows_result2 = $result2->RecordCount();
if ($totalRows_result1 < 1) {
echo 'sorry, category 1 has no items';
}
if ($totalRows_result2 < 1) {
echo 'sorry, category 2 has no items';
}