I'm trying to get two sets of row count.
One with the total number of rows in a specific table, and a second count on the number of rows returned based on a WHERE
statement - from the same table.
It's a basic thing I guess. The text says "We have ### number of partners, and ## of them are displayed on your site". I also need to retrieve data, and not just the row-counts.
Do I have to make multiple SQL-queries to the database? or is there a more efficient way to collect this info from on SQL-query?
My queries looks like this:
$visable_dealers = $pdo->query('SELECT COUNT(1) FROM dealers WHERE visable = 1')->fetchColumn();
$all_dealers = $pdo->query('SELECT * FROM dealers')->fetchAll();
I could do a foreach
-loop, and then add +1
to a variable every time $val['visable']
is equal to 1
. But I would get that number too late. I need it before the loop.