Alright, I made a demo of this since I was interested in figuring it out myself. You can see the example at: http://stclement.compucastweb.com/test/ Feel free to enter a couple entries. It will only be online for a day or so and then I will take it down.
So, the way this works is every 5 seconds an ajax request is made to a server side script, in the case of the demo, fetch.php. The php file serves two main purposes, storing a session and fetching data. The session contains a row count from the entry table. Every time the file is accessed it checks to see if the current row count is equal to your session row count. If they are not equal than the file queries the database for the difference of the new total and your sessions total. Finally it updates your session total with the new total.
Each time the index page (entry listing page) is loaded it sets the sessions total to 0, ensuring that fetch.php will produce results. When the fetch function runs and successfully returns data it will remove any entry past 10. This is to keep the page from getting ridiculously long. The new entry will be appended to the list and I have it set to fade in purely for aesthetic purposes.
Also, I used jQuery to tie it all together, feel free to create your own functions for handling the http request and dom manipulation. Below is the source code.
index.php
<?php
session_start();
$_SESSION["total"] = 0;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Entry list</title>
<style>
#list, p, h1{
border:1px solid #CCCCCC;
padding:10px;
margin:10px;
}
#list p{
display:none;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>
function fetch(){
$.ajax({
url: 'fetch.php',
success: function(data) {
$("#list").prepend(data);
if($("#list p").length > 10){
$('#list p:gt(9)').remove();
}
$("#list p").fadeIn();
setTimeout("fetch()", 5000);
}
});
}
$(function(){
fetch();
});
</script>
</head>
<body>
<h1>Entry List</h1>
<p>Entries are updated every 5 seconds. A max total of 10 entries can be shown at a time. The newest entries are shown first, if a new entry makes the list extend past 10 then the oldest entry will be removed from the bottom and the new entry will be appended to the top. Feel free to add a new entry in a new tab, once you submit it the entry will be shown ~5 seconds later in the list for users who are currently viewing the listing page, otherwise it will show imediately on page load.</p>
<p>» <a href="submit.php" target="_blank">Add a new Entry</a></p>
<div id="list">
<p>Loading...</p>
</div>
</body>
</html>
fetch.php
<?php
session_start();
include($_SERVER['DOCUMENT_ROOT']."/config.php");
$sql = "SELECT COUNT(`entry_id`) AS total_entries
FROM `entries`";
$result = mysql_fetch_assoc(mysql_query($sql));
$total_entries = $result["total_entries"];
if($_SESSION["total"] != $total_entries){
$limit = $total_entries - $_SESSION["total"];
$sql = "SELECT *
FROM `entries`
ORDER BY `entry_id` DESC
LIMIT ".$limit;
$result = mysql_query($sql);
if(mysql_num_rows($result)>0){
while($row = mysql_fetch_assoc($result)){
echo "<p>".$row["entry_title"]."</p>";
}
}
$_SESSION["total"] = $total_entries;
}
?>
And, if your curious, the source for submit.php
<?php
include($_SERVER['DOCUMENT_ROOT']."/ccms_config.php");
include($admin_sys_path."/functions.php");
$msg = "";
if(isset($_POST["submit"])){
$sql = "INSERT INTO entries
(`entry_title`)
VALUES
('".secure($_POST["title"])."')";
mysql_query($sql);
$msg = "<p>Success! Entry submitted.</p>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Submit</title>
<style>
fieldset, p, h1{
border:1px solid #CCCCCC;
padding:10px;
margin:10px;
}
</style>
</head>
<body>
<h1>Submit an Entry!</h1>
<?php if(!empty($msg)){ echo $msg; } ?>
<form method="post" action="submit.php">
<fieldset>
<legend>Entry Form</legend>
<label for="title">Test Title:</label>
<input type="text" name="title" />
<input type="submit" name="submit" value="Submit" />
</fieldset>
</form>
</body>
</html>
Hope this is helpful.