mcfc4heatons Posted June 1, 2022 Share Posted June 1, 2022 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'; } Quote Link to comment https://forums.phpfreaks.com/topic/314873-php-adodb-check-if-query-returnd-results-with-two-differenct-conditions/ Share on other sites More sharing options...
Barand Posted June 1, 2022 Share Posted June 1, 2022 select catid , count(*) as total from table group by catid Quote Link to comment https://forums.phpfreaks.com/topic/314873-php-adodb-check-if-query-returnd-results-with-two-differenct-conditions/#findComment-1596913 Share on other sites More sharing options...
ginerjm Posted June 1, 2022 Share Posted June 1, 2022 Or how about select cat1, count(cat1) as tot_cat where cat1=1 or cat1=2 group by cat1 giving you at most 2 rows showing the value of cat1 and the count of recs with that value Quote Link to comment https://forums.phpfreaks.com/topic/314873-php-adodb-check-if-query-returnd-results-with-two-differenct-conditions/#findComment-1596915 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.