How to get counts of posts and comments?
-
I have a static front page that contains links to several blogs. To the right of the blog title on this front page I want to display the total number of posts and comments for each blog. What is the best way to get these totals?
Below is what I am thinking of at the moment, but may not be effiecient. Is there a better way? Other ideas?
<?php
@ $db = mysql_connect('localhost','username','password');
if (!$db)
{
exit;
}
mysql_select_db('wp21');$qryblog21_posts = "select count(*) -1 as ct from wp01_posts";
$qryblog21_comments = "select count(*) -1 as ct from wp01_comments";$result21_posts = mysql_query($qryblog21_posts);
$result21_comments = mysql_query($qryblog21_comments);$array21_posts = mysql_fetch_array($result21_posts);
$array21_comments = mysql_fetch_array($result21_comments);mysql_close;
if ($array21_posts && $array21_comments)
{
echo $array21_posts[0];
echo "</br>";
echo $array21_comments[0];
}
?>Any suggestions welcome.
Thanks in advance.
- The topic ‘How to get counts of posts and comments?’ is closed to new replies.