<?php

// Configure connection settings

$db = 'asteriskcdrdb';
$db_admin = 'dbuser';
$db_password = 'dbpassword';
$tablename = 'cdr';

// Title

echo "Call History (last 5 calls)<br /><br />";
echo "<table class='table table-condensed table-striped'>";
echo "<tr><th>date</th><th>from number</th><th>to number</th><th>call length </th></tr>";

// Connect to DB

$sql = mysql_connect("localhost", $db_admin, $db_password)
or die(mysql_error());

mysql_select_db("$db", $sql);

// Fetch the data

$query = "SELECT * FROM $tablename ORDER BY calldate DESC LIMIT 5";
$result = mysql_query($query);

// Return the results, loop through them and echo

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{
$calltime = gmdate("H:i:s",$row['billsec']);
echo "<tr><td>{$row['calldate']}</td>" .
"<td>{$row['src']}</td>" .
"<td>{$row['dst']}</td>" .
"<td>{$calltime}</td></tr>";
}

echo "</table>";

?>
