15 Apr, 2004
Average Posts Per Day
Posted by: Jennifer In: Scripts
I wrote this little snippet of code to display my average posts per day on my journal. Unfortunately that number turned out embarrassingly small (0.383) so I added functionality to display how many days between posts (a post every 2 days looks better). Just uncomment the echo you prefer.
Requires PHP and MySQL.
<?
// average posts per day script written by michelle of http://usr-bin-mom.com
// check out my pregnancy script and firstyear script on http://scriptygoddess.com
// linkbacks appreciated
mysql_connect ('localhost', 'USERNAME', 'PASSWORD') ;
mysql_select_db ('DATABASE');
$result = mysql_query ("SELECT * FROM TABLE");
$num_rows = mysql_num_rows($result);
mysql_close();
$first_post = "March 7, 2000";
$today = strtotime ("today");
$start = strtotime ("$first_post");
$difference = $today – $start ;
$days = intval($difference/86400);
$posts_per_day = $num_rows/$days;
$days_per_post = $days/$num_rows;
// echo "I average <b>$posts_per_day</b> posts per day.";
// echo "I average one post every <b>$days_per_post</b> days.";
?>