/*
* GetStats
* Fetches the visitor statistics totals from the database
*/
$tmpArray = $modx->getSiteStats();
$output = "
<table id='stats' cellspacing='1' cellpadding='5'>
<tr>
<td class='toprow'> </td>
<td class='toprow'>Page Impressions</td>
<td class='toprow'>Visits</td>
<td class='toprow'>Visitors</td>
</tr>
<tr>
<th>Today</th>
<td>".number_format($tmpArray['piDay'])."</td>
<td>".number_format($tmpArray['visDay'])."</td>
<td>".number_format($tmpArray['viDay'])."</td>
</tr>
<tr>
<th>This Month</th>
<td>".number_format($tmpArray['piMonth'])."</td>
<td>".number_format($tmpArray['visMonth'])."</td>
<td>".number_format($tmpArray['viMonth'])."</td>
</tr>
<tr>
<th>All Time</th>
<td>".number_format($tmpArray['piAll'])."</td>
<td>".number_format($tmpArray['visAll'])."</td>
<td>".number_format($tmpArray['viAll'])."</td>
</tr>
</table>
";
return $output;$username="your_db_username"; $password="your_db_password"; $database="your_db_name"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $sql = "SELECT COUNT(*) FROM modx_log_access WHERE document=$pageNum"; $rs = mysql_query($sql); $tmp = mysql_fetch_assoc($rs); $piAll = $tmp['COUNT(*)']; mysql_close(); echo "<p class='totalpageviews'>This page has been viewed: $piAll times</p>";

:o:o Page contains mild adult content.
:o:o
$pageNum = $modx->documentObject['id'];
$table = $modx->getFullTableName("log_access");
$results = $modx->db->select("count(*)", $table, "document=$pageNum");
$piAll = mysql_result($results,0);
echo "<p class='totalpageviews'>This page has been viewed: $piAll times</p>";
Starbuck, here is an updated version of your code that uses the modx api so you don’t need all of the mysql conenct stuff and the username and password.
$pageNum = $modx->documentObject['id']; $table = $modx->getFullTableName("log_access"); $results = $modx->db->select("count(*)", $table, "document=$pageNum"); $piAll = mysql_result($results,0); echo "<p class='totalpageviews'>This page has been viewed: $piAll times</p>";
Kyle
I don’t know if this stat stuff has been done before. I just thought this would be much easier using the api so I did the modification.
Kyle
