SQL for counting comments - is this smart?
[email protected] (Martin Zvarík)
| Newsgroups | php.db |
|---|---|
| Message-ID | <[email protected]> |
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);