Du starter med at lægge din kode over i en php fil:
<?php
$sql = "select * FROM Bruger_tabel WHERE Userid = '". $_SESSION['Id'] ."'";
$result = mysql_query($sql, $conn) or die (mysql_error());
$newArray = mysql_fetch_array($result);
//Så gør du at php filen udskriver dine data:
echo $newArray;
?>
Kald den besked.php
Så ovre i dit besked vindue indsætter du dette:
<html>
<head>
<meta http-equiv="Content-Language" content="da">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Ny side 1</title>
<script type="text/javascript" language="JavaScript">
var http=null;
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sendReq(){
http.open('get', 'besked.php');
http.onreadystatechange = handleProducts;
http.send(null);
}
function handleProducts(){
if(http.readyState == 4){ //Finished loading the response
var response = http.responseText;
document.getElementById('beskedlabel').innerHTML = response;
}
setTimeout("sendReq()",5000);
}
</script>
</head>
<body onLoad="sendReq()">
<tr>
<td>
<div id="beskedlabel">
</div>
</body>
</html>
Denne koden opdatere hver 5 sec
Indlæg senest redigeret d. 11.08.2007 11:10 af Bruger #11573