I has some question about live database.
that mean when database change that value, the page will show directly something like Live Chat.
Language : Jquery + PHP
Example:
MySQL Database:
Table : user
column : username,Status,Date,TodayOnline
Data : [Kenny, Online,15/03/2013,0],[David, Offline,16/03/2013,1]
Action:
When David going to online, it will show at page directly by using replace the "Kenny is now Online" with "David is now online"
and show Today online time mean how many time he is only today.
Screen Show:
David Is Now Online (Today Online : 1)
Wish you guy understand what i mean, i dont know how to do it by ajax,or who can tell me how to make ajax run every second or any other good idea to show it instant/live?
Thanks in Advance.
UPDATE
Here is my code JS
$.ajax({
type: "post",
url: "/checkOnline.php",
cache: false,
data:{ date: $("#date").val(),time: $("#time").val()},
success: function(responds){
var obj = JSON.parse(responds);
try{
('#online').text(responds+" Is Now Online");
}catch(e){
alert('Exception while request..');
}
},
error: function(XMLHttpRequest, textStatus, errorThrown){
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
});
Here and my index code i adding hiding input box for get current date time.
<input name="date" id="date" value="<?= date('Y-m-d') ?>" style="display:none"/>
<input name="time" id="time" value="<?= date('H:i:s') ?>" style="display:none"/>
and this is my checkOnline.php
<?php
$query = "Select username FROM user WHERE status='online'";
$result = mysql_query($query);
echo json_encode($result)
?>
i run the ajax when someone load the page using jquery but i know this is a bad idea, but i dont know how to make it live.
Thanks