Jump to content

Recommended Posts

Hi,

 

 

Make a index.php,

 

<html>

<head>
<script type="text/javascript">
function Ajax(){
var xmlHttp;
try{	
	xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
}
catch (e){
	try{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
		xmlHttp = null;
	}
	catch (e){
	    try{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");


		}
		catch (e){
			alert("No AJAX!?");
			return false;
		}
	}
}

xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
	document.getElementById('content').innerHTML=xmlHttp.responseText;
	xmlHttp = null;
	setTimeout('Ajax()',1000);
	}
}
xmlHttp.open("GET","data.php' );
xmlHttp.send(null);
}

window.onload=function(){
setTimeout('Ajax()',1000);
}


</script>

</head>
<body>

Hi this is home page

</body>
</html>

 

 

If you observe the above code, javascript have called the data.php file, so that u can live value from the database, without refreshing

 

//data.php is called in the interval of 1 second, so u wil get the updated values from the database

 

//ajax is called with the interval of 1 second in the div panel name "content"

 

<?php
echo "<div id="content">";
//select query 
//echo "column";
echo "</div>";
?>

 

 

All the best

 

Link to comment
https://forums.phpfreaks.com/topic/231106-mysql-live-update/#findComment-1189838
Share on other sites

  • 4 weeks later...

Hmm... I just copy pasted the index, added the content div and the data file but I got nothing good.

What did I do wrong?  ;)

<html>

<head>
<script type="text/javascript">
function Ajax(){
var xmlHttp;
try{	
	xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
}
catch (e){
	try{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
		xmlHttp = null;
	}
	catch (e){
	    try{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");


		}
		catch (e){
			alert("No AJAX!?");
			return false;
		}
	}
}

xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
	document.getElementById('content').innerHTML=xmlHttp.responseText;
	xmlHttp = null;
	setTimeout('Ajax()',1000);
	}
}
xmlHttp.open("GET","data.php' );
xmlHttp.send(null);
}

window.onload=function(){
setTimeout('Ajax()',1000);
}


</script>

</head>
<body>

Hi this is home page
<div id=content>

</div>

</body>
</html>

 

Link to comment
https://forums.phpfreaks.com/topic/231106-mysql-live-update/#findComment-1201715
Share on other sites

  • 1 year later...

Hi PHPMady, I wanted to thank you for your post even if it's from long time ago... But this one helped me a lot and it worked fine.

We just want to make sure to note that the last PHP piece of code can be inserted in the index.php page right underneath the "Hi, this is homepage"  line.

Also, the data.php is another file that users should already have to have with their Database connection code and the query that pulls the data from the mysql.

 

Now, this is a working example that is great.

 

I just need help with a multi-liner instead of one line.

 

What if I have 50 records and I want to refresh the whole display table instead of only one record? What code do I need and where do I need it?

 

Thanks for your help.

 

 

Link to comment
https://forums.phpfreaks.com/topic/231106-mysql-live-update/#findComment-1341926
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.