• 0

Refreshing DIV in PHP


Question

Right, im trying to get a div to auto refresh on my webpage.

Here is the code

  <div class="Box">
  <h2>Forum Stats</h2>
  <?php include 'php/forumstats.php';?>  </div>

This sits in index.php

I've tried over 10 different guides on the net and none work!

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

Having your page refresh has nothing to do with PHP. Can you elaborate on exactly what you're trying to do? You're including a file which could have anything in it, and the result will be your coded HTML plus whatever is in php/forumstats.php in your browser. Are you wanting to have your page refresh after a certain number of seconds? Are you wanting to content to automatically update without the page actually refreshing?

Link to comment
Share on other sites

  • 0

The include just pulls out stats from a DB. such as last post etc. Obviously this updates when you refresh the page.

Im not saying it has anything to do with PHP, its either JS or ajax. But i need a script to either refresh a div or a php include.

I'd like to be able to set it to auto refresh just this div (which in turn reloads the include) every X seconds.

Can talk on MSN if you are willing to help? I'dd add you if you ok it!

Link to comment
Share on other sites

  • 0
The include just pulls out stats from a DB. such as last post etc. Obviously this updates when you refresh the page.

Im not saying it has anything to do with PHP, its either JS or ajax. But i need a script to either refresh a div or a php include.

You can't refresh a DIV, nor any other HTML element "on the fly" without any scripting.

You CAN refresh the entire page using a script or the meta refresh element.

You can also have a script get data from a server and have it write this data to the page at set intervals. This is also known as AJAX.

Link to comment
Share on other sites

  • 0
You can't refresh a DIV, nor any other HTML element "on the fly" without any scripting.

You CAN refresh the entire page using a script or the meta refresh element.

You can also have a script get data from a server and have it write this data to the page at set intervals. This is also known as AJAX.

Fine, im incorrect with the process.

Include outputs figures. I would like said figures to refresh on the page without loading the whole lot! If that is ajax, then let me use ajax. Just tell me how! lol

Link to comment
Share on other sites

  • 0

You could use an iframe, put the src to your php page. Have the php page do a meta refresh. In the end you will have an iframe that will refresh the php page. Make sense, the current solution is only setup to meta refresh in IE.

Embed this in the page where you want to show the contents of the php page:

<iframe width="468" height="60" src="https://clients.seadoosportboats.com/vendors.php" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe>

Make your php page look something like this:

<html>
<head>
<script language="javascript">
<!--
if (navigator.appName == "Microsoft Internet Explorer")
document.write('<META HTTP-EQUIV=Refresh CONTENT="30" />');
-->
</script> 
</head>
<body bgcolor="#FFFFFF" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td>
<a href='http://clients.seadoosportboats.com/clientserver/www/delivery/ck.php?n=a770acb9&cb=1002' target='_blank'>
<img src='http://clients.seadoosportboats.com/clientserver/www/delivery/avw.php?campaignid=5&source=SeaDooSportBoats.com&cb=1002&n=a770acb9' border='0' alt='Salt-Away Products, Inc.' title='Salt-Away Products, Inc.' /></a>
</td>
</tr>
</table>
</body>
</html>

I have coded it so it will only meta refresh with IE, you could change this if you would like. See if this helps at all. :)

Link to comment
Share on other sites

  • 0

Just search for a simple ajax script. This is the whole point of AJAX, refresh only the part of the page you wish to refresh. The timer can be done in the javascript to launch the request to the server, but worry about that part last. If you don't want to get your hands dirty with some simple ajax, there are plenty of ajax frameworks you could use instead.

Link to comment
Share on other sites

  • 0
Just search for a simple ajax script. This is the whole point of AJAX, refresh only the part of the page you wish to refresh. The timer can be done in the javascript to launch the request to the server, but worry about that part last. If you don't want to get your hands dirty with some simple ajax, there are plenty of ajax frameworks you could use instead.

I'd love to see one then!

I've tried loads of ajax guides and prebuild code and none of them work.

So if you have one that does, please let me know

Link to comment
Share on other sites

  • 0
Thanks! I'll try it now.

What about other browsers too!

Like I said you should be able to modify it, you just need to do a little reading on your own. Read about navigator.appName.

<script language="javascript">
<!--
if (navigator.appName == "Microsoft Internet Explorer")
document.write('<META HTTP-EQUIV=Refresh CONTENT="30" />');
-->
</script>

Let us know what approach you take and if you get it working.

Link to comment
Share on other sites

  • 0

Check out a library like jQuery, which I use extensively at work and for my own sites. Read up on the library's documentation. If you don't know javascript, now would be a good time to learn, it's quite an easy language to pick up.

In jQuery, it's simple as using this code on your main page.

<head>
  <script type="text/javascript" language="javascript" src="js/jQuery.js"></script>
  <script type="text/javascript" language="javascript">
	function updateForumStats() {
	  $.get("php/forumstats.php", function(data) {
		$("#forumstats").html(data);
		  });
   	  window.setTimeout("updateForumStats();", 10000);
	}

	$(document).ready(function() {
	  updateForumStats();
	});
  </script>
</head>

You can play with the "10000" (the 2nd argument of the window.setTimeout() function, which is in milliseconds) to have it refresh as often as you'd like.

Edited by jimbo11883
Link to comment
Share on other sites

  • 0

Thanks for the help guys. I'm using the iframe for the moment, not idea but it does the job. I'm going to look into learning javascript.

You need to use target="_parent" for it to open in the page not the iframe too.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.