Nah, i will (eventually) develop this into a full shoutbox service...
Just need some Ajax to reget posts from the db.
Found this on one of the pages would it do it?
Code:
<script type="text/javascript">
var page = "online.php";
function ajax(url,target) {
// native XMLHttpRequest object
document.getElementById(target).innerHTML = 'Loading...';
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = function() {ajaxDone(target);};
req.open("GET", url, true);
req.send(null);
// IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLDOM");
if (req) {
req.onreadystatechange = function() {ajaxDone(target);};
req.open("GET", url, true);
req.send(null);
}
}
setTimeout("ajax(page,'scriptoutput')", 5000);
}
function ajaxDone(target) {
// only if req is "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200 || req.status == 304) {
results = req.responseText;
document.getElementById(target).innerHTML = results;
} else {
document.getElementById(target).innerHTML="ajax error:\n" +
req.statusText;
}
}
}
</script>
This is the PHP code:
PHP Code:
echo '<div id="right_side">'; if (!isset($_GET['pagenum'])) { $pagenum = 1; } else { $pagenum = $_GET['pagenum']; } $result = mysql_query("SELECT * FROM messages WHERE shoutbox_id='$shoutbox_id' ORDER BY datetime DESC") or die("ERROR:".mysql_error());
$rows = mysql_num_rows($result); //This is the number of results displayed per page $page_rows = $shoutbox['post_per_page']; //This tells us the page number of our last page $last = ceil($rows/$page_rows); //this makes sure the page number isn't below one, or more than our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //This sets the range to display in our query $max = 'ORDER BY datetime DESC LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows; //This is your query again, the same one... the only difference is we add $max into it $messages_res = mysql_query("SELECT * FROM messages WHERE shoutbox_id='$shoutbox_id' $max") or die("ERROR:".mysql_error()); while($msg = mysql_fetch_array($messages_res)) { $msg['datetime'] = strtotime($msg['datetime']); $msg['datetime'] = date('d/m/Y H:i', $msg['datetime']); echo '<div class="message">'; echo '<span class="msg_user">'.wordwrap($msg['user'],12, "<br />\n", true).':</span><br />'; echo wordwrap($msg['msg'], 18, "<br />\n", true).'<br /> <span class="smltxt">'.$msg['datetime'].'</span> <br /> </div>'; } echo '</div>'; /* Pagination links */ echo '<span id="links">'; if ($pagenum != 1 && $pagenum != 0) { $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?sb=".$_GET['sb']."&pagenum=$previous'>".$shoutbox['prev_name']."</a> "; } for($i = 1; $i <= $last; $i++) { echo " <a href='{$_SERVER['PHP_SELF']}?sb=".$_GET['sb']."&pagenum=$i'> $i</a> "; } //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links if ($pagenum != $last) { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?sb=".$_GET['sb']."&pagenum=$next'>".$shoutbox['next_name']."</a> "; } echo '</span>';
(this is just the part which needs refreshing.)
Dan
__________________
Personal UK Webhosting Get 25% of ANY shared package for life ~ Promo: webmaster-talk
|