|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php function getNewMessagesSince($timestamp) { if(rand(1,20) == 5) { return array( 'lastupdate' => time(), 'html' => '<p>server is still alive at '.date('Y-m-d H:i:s').'</p>' ); } return false; } while(!($row = getNewMessagesSince($_POST['lastupdate']))) { // warte 0.2 Sekunden um den Server zu entlasten usleep(200000); } // liefere den Inhalt echo json_encode($row); |
|
|
XML Code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
function getNewMessagesSince($timestamp) { $lastupdate = array(); $html = ''; $sql = 'SELECT feld1, feld2, feld3, time FROM nachrichten WHERE time > '.intval($timestamp); $res = mysql_query($sql); while ($row = mysql_fetch_array($res)) { $lastupdate = $row['time']; $html .= '<li>'.$row['feld1'].'</li>'; } if(count($lastupdate)) { rsort($lastupdate); return array( 'lastupdate' => array_shift($lastupdate), 'html' => $html ); } return false; } |
|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?php function getNewMessagesSince($timestamp) { $lastupdate = array(); $html = ''; $sql = 'SELECT feld1, time, feld3 FROM nachrichten WHERE time > '.intval($timestamp); $res = mysql_query($sql); while ($row = mysql_fetch_array($res)) { $lastupdate = $row['time']; $html .= '<li>'.$row['feld3'].'</li>'; } if(count($lastupdate)) { rsort($lastupdate); return array( 'lastupdate' => array_shift($lastupdate), 'html' => $html ); } return false; } while(!($row = getNewMessagesSince($_GET['lastupdate']))) { usleep(200000); } echo json_encode($row); ?> |
This post has been edited 1 times, last edit by "gcon" (Apr 3rd 2011, 5:07pm)
|
|
PHP Quellcode |
1 |
print_r(getNewMessagesSince($_GET['lastupdate'])); |
|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?php function getNewMessagesSince($timestamp) { $lastupdate = array(); $html = ''; mysql_select_db($Name, $connect); mysql_query("set names utf8"); $sql = 'SELECT id, time, nachricht FROM nachrichten WHERE time > '.$timestamp; $res = mysql_query($sql); while ($row = mysql_fetch_array($res)) { $lastupdate = $row['time']; $html .= '<li>'.$row['nachricht'].'</li>'; } if(count($lastupdate)) { rsort($lastupdate); return array( 'lastupdate' => array_shift($lastupdate), 'html' => $sql ); } return false; } print_r(getNewMessagesSince($_GET['lastupdate'])); ?> |
|
|
PHP Quellcode |
1 |
$lastupdate[] = $row['time']; |
|
|
PHP Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?php function getNewMessagesSince($timestamp) { $lastupdate = array(); $html = ''; $sql = 'SELECT id, time, nachricht FROM nachrichten WHERE time > '.$timestamp; $res = mysql_query($sql); while ($row = mysql_fetch_array($res)) { $lastupdate[] = $row['time']; $html .= '<li>'.$row['nachricht'].'</li>'; } if(count($lastupdate)) { rsort($lastupdate); return array( 'lastupdate' => array_shift($lastupdate), 'html' => $html ); } return false; } while(!($row = getNewMessagesSince($_GET['lastupdate']))) { usleep(200000); } echo json_encode($row); ?> |
|
|
PHP Quellcode |
1 2 3 4 5 6 7 |
$Host = ""; $User = ""; $Pw = ""; $Name = ""; $connect = @mysql_connect($Host, $User, $Pw) or die("Fehler!"); mysql_select_db($Name, $connect); mysql_query("set names utf8"); |
|
|
JavaScript Code |
1 2 3 4 5 6 7 8 9 10 |
var lastupdate = Math.round((new Date()).getTime() / 1000); $.ajax({ type:'POST', url:'/nachrichten.php', data:'lastupdate='+lastupdate, contentType: "application/x-www-form-urlencoded;charset=ISO-8859-15", success:function(response){ $("#nachrichten").append(response); } }); |