PHPBuilder - Storing Data in the Client Page 4



RSS Twitter
Articles Tricks And Hacks

Storing Data in the Client - Page 4

by: PHP Builder Staff
|
July 30, 2000

PHP & JavaScript World Domination Series: Storing data in the client.

The loader frame is next:

<?php

session_start
(); // We use Sessions here!

if(!isset($timestamp)) {
    
//If no timestamp set we define it as 0
    
$timestamp=0;    
}

$dab=mysql_connect("localhost","user","password");  // Use your own values here
mysql_select_db("testbase",$dab);

// Query the messages not seen by the client
$query="select * from testeable where timestamp>'$timestamp'";
$result=mysql_query($query,$dab);
$msgs=array();

// In the loop we store the messages in an array and also get the 
// maximum timestamp
while($res=mysql_fetch_array($result)) {
    
$msgs[]=$res["message"];
    if(
$res["timestamp"]>$timestamp) {
        
$timestamp=$res["timestamp"];
    }
}
session_register("timestamp"); // Register the timestamp

echo '<script>';

// In this loop we generate JavaScipt Code to 
// Add the messages to the array in "master" (note the use of "top"
// to refer to the parent frame which is master)
for($i=0;$i<$count($msgs);$i++) {
    
?>
    top.lines[top.lines.length]="<?php print("$msgs[$i]"); ?>";
    <?php


// Now we'll generate JS code to make the display frame reload.

?>
top.display.location.reload();
</script>

<!-- Note the JS setInterval method to make this frame reload each 4 seconds -->
<body onLoad="window.setInterval('location.reload()',4000);">
</body>


« Previous Page
1
|
2
|
3
|
4
|
5
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:

Comment:



Comment:

(Maximum characters: 1200). You have characters left.