SQL for counting comments - is this smart?
| From: | Martin Zvarík | Date: | Tue, 17 Mar 2009 01:03:28 +0000 |
| Subject: | SQL for counting comments - is this smart? | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-46080@lists.php.net to get a copy of this message | ||
Is it smart to use all of this on one page?
Or should I rather do one SQL and let PHP count it?
$q = $DB->q("SELECT COUNT(*) FROM comments");
$int_total = $DB->frow($q);
$q = $DB->q("SELECT COUNT(*) FROM comments WHERE approved IS NULL");
$int_waiting = $DB->frow($q);
$q = $DB->q("SELECT COUNT(*) FROM comments WHERE approved=0");
$int_deleted = $DB->frow($q);
$q = $DB->q("SELECT COUNT(*) FROM comments WHERE approved=1");
$int_approved = $DB->frow($q);
$q = $DB->q("SELECT COUNT(*) FROM comments WHERE approved=2");
$int_banned = $DB->frow($q);