PHP - Meta Refresh Issue

I have an html page with an included php script in a DIV
This brings in the contents of who.php
I need who.php to refreash every 45 seconds so I used the code below.

The problem is that it refreshes the entire html page every 45 seconds also.

I really wanted to use include instead of Iframe, how can I accomplish just that single "who.php" page refreshing and not the html?
The include
<?php include( 'includes/who.php' ); ?>

Refresh Code
<meta http-equiv="refresh" content="45">

Open in new window

mimoserAsked:
Who is Participating?
 
GawaiConnect With a Mentor Commented:
alternative way

index.php

<html>  
<head> 
<meta http-equiv="X-UA-Compatible" content="IE=7"/> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<style> 
.body { 
color: #00ff00; 
font-family: Verdana, Arial; 
font-size: 12px; 
font-style: normal; 
background-color: #000000; 
} 
a:link {text-decoration: none; color: #00ff00;} 
a:visited {text-decoration: none; color: #00ff00;} 
a:active {text-decoration: none; color: #00ff00;} 
a:hover {text-decoration: underline; color: #00ff00;} 
</style> 
 
 
<script> 
setTimeOut(4500, "refreshWho()"); 
function refreshWho(){ 
$("#divWho").load("who.php", function(){setTimeOut(4500, "refreshWho()");}); 
} 
</script> 
 
 
</head> 
<body class="body" marginwidth="0" marginheight="0" leftmargin="0" rightmargin="0" topmargin="0" background-color:"#000000" bottommargin="0"> 
&nbsp;<center> 
 
<br><br> 
<img src="images/lbh.png"> 
        <iframe id="loadpage" src="index.php" align="center" width="810" height="850" frameborder="0" scrolling="no" style="background-color: #000000;border: 1px solid #000000;"> 
                <p>Your browser does not support iframes.</p> 
        </iframe> 
         
<br><br><br> 
<div id=divWho>

<?php
include('who.php');
?>

</div> 
        </center><br><br> 
</body> 
</html>

Open in new window

0
 
HainKurtSr. System AnalystCommented:
hmms...

i do this:

put and iframe on your page

<iframe src="who_whole.php" style="width:500; height:400;">no iframe</iframe>

create who_whole.php - based on who.php (probably need to add some header & footer to who.php)
and put <meta http-equiv="refresh" content="45"> in who_whole.php

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
HainKurtSr. System AnalystCommented:
the other option is jQuery (not tested may have syntax error ;)

<script>
setTimeOut(4500, "refreshWho()");
function refreshWho(){
$("#divWho").load("who_whole.php", function(){setTimeOut(4500, "refreshWho()");});
}
</script>

<div id=divWho>
<?php include( 'includes/who.php' ); ?>
</div>
0
 
mimoserAuthor Commented:
Those solutions are using IFRAMES is there a way to skip IFRAME, maybe with a simple AJAX solution?
0
 
Shinesh PremrajanTechnical ManagerCommented:
The answer suggested by HainKurt is correct, A small correction here is

<div id=divWho>
<?php include( 'includes/who.php' ); ?>
</div>

should be

<div id=divWho></div>

And the rest of the Jquery script as suggested.

Hope this clarifies

0
 
mimoserAuthor Commented:
Well.. I'm not sure about the whole_who.php page..is that needed?

Right now I have who.php which needs to pull data from the SQL every 45 seconds and show it in a DIV on index.html

the include was working, but refreashed the entire page. I just need the DIV refreashed.

I placed

<script>
setTimeOut(4500, "refreshWho()");
function refreshWho(){
$("#divWho").load("who.php", function(){setTimeOut(4500, "refreshWho()");});
}
</script>

^^ changed to who.php^^
In the head of my index.html

and where I wanted the DIV I placed

<div id=divWho></div>

This caused nothing to be displayed. Did I do this wrong?
0
 
GawaiCommented:
In your who.php put this code on top

<meta http-equiv="refresh" content="45;URL=http://www.yoursite.com/who.php">
0
 
mimoserAuthor Commented:
That is, however the entire DIV is not showing up.
0
 
GawaiCommented:
post your complete code pls
0
 
mimoserAuthor Commented:
Below is the index.html and who.php
index.html
<html> 
<head>
<meta http-equiv="X-UA-Compatible" content="IE=7"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
.body {
color: #00ff00;
font-family: Verdana, Arial;
font-size: 12px;
font-style: normal;
background-color: #000000;
}
a:link {text-decoration: none; color: #00ff00;}
a:visited {text-decoration: none; color: #00ff00;}
a:active {text-decoration: none; color: #00ff00;}
a:hover {text-decoration: underline; color: #00ff00;}
</style>


<script>
setTimeOut(4500, "refreshWho()");
function refreshWho(){
$("#divWho").load("who.php", function(){setTimeOut(4500, "refreshWho()");});
}
</script>


</head>
<body class="body" marginwidth="0" marginheight="0" leftmargin="0" rightmargin="0" topmargin="0" background-color:"#000000" bottommargin="0">
&nbsp;<center>

<br><br>
<img src="images/lbh.png">
	<iframe id="loadpage" src="index.php" align="center" width="810" height="850" frameborder="0" scrolling="no" style="background-color: #000000;border: 1px solid #000000;">
  		<p>Your browser does not support iframes.</p>
	</iframe>
	
<br><br><br>
<div id=divWho></div>
	</center><br><br>
</body>
</html>


who.php --

<meta http-equiv="refresh" content="45">
<?php 
	include("db.php");
	include("config.php");
	include("functions.php");
	$cp_userOffline = date("U")-30;
	if($_GET['cp_search_online']){
		$cp_doSearch = "WHERE online_time >='".$cp_userOffline."'";

	}

?>
<?php 
	$tmp=mysql_query("
	SELECT *     
	FROM ".$CONFIG['mysql_prefix']."user
	WHERE online_time >= '".$cp_userOffline."'  
	ORDER BY id DESC 
	") or die(mysql_error()); 

	$cp_totalOnline = mysql_num_rows($tmp);

	if($cp_totalOnline < 10){

		$cp_totalOnline = '0'.$cp_totalOnline;

	}

?>
  <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body bgcolor="#000000">
 <div class="lbh" align="center" style="width: 800px; height: 35px;"></div>
<div class="lb" align="center" style="width: 800px; height: 200px"><p>
<tr><td><center><b>Users Online: <font color=lime><?php echo $cp_totalOnline;?><br>
-45 Sec. Delay</font></b></center></td></tr>
<img src="../images/who_line.gif" width="200" height="5" border="0" alt=""> <br>
<?php 
 
                while($got_data = mysql_fetch_array($tmp)) { 
 
                        $cp_username = $got_data['username']; 
                        $cp_online_time = $got_data['online_time']; 
                        $cp_gender = $got_data['gender'];
                        $cp_tag = $got_data['tag']; 
 
                        if($cp_online_time > (date("U")-30)){ 
 
                                $cp_isOnline = '<font color=green>Online</font>'; 
 
                        }else{ 
 
                                $cp_isOnline = '<font color=red>Offline</font>'; 
 
                        } 
 
                        ?> 



                         
                        
                        
                    
                        
                        
                        
      <?php                  
if(!empty($cp_tag))
{
   echo $cp_tag;
}
else{ 
if($cp_gender > 1) {
  echo "<font size=\"4\" color=\"#FF0099\">".$cp_username."</font>" ; 
}else{
echo "<font size=\"4\" color=\"lime\">".$cp_username."</font>" ;
}
}
     ?>       
 
     <br> <tr><td height="9" colspan="3"> 
<img src="../images/who_line.gif" width="200" height="5" border="0" alt=""> <br>
</td></tr> 
           
     
                
                       
 
                 
                        <?php 
 
                } 
 
                ?>
</p><br></div> 
 <div class="lbb" align="center" style="width: 800px; height: 35px;"></div><br><br>
</body>
</html>

Open in new window

0
 
GawaiCommented:
try with this one.
0
 
mimoserAuthor Commented:
my index.html is now below.. but no div or external page shows up and gives me the error of " null or not  object" for this line

document.getElementById(containerid).innerHTML=page_request.responseText


<meta http-equiv="X-UA-Compatible" content="IE=7"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
.body {
color: #00ff00;
font-family: Verdana, Arial;
font-size: 12px;
font-style: normal;
background-color: #000000;
}
a:link {text-decoration: none; color: #00ff00;}
a:visited {text-decoration: none; color: #00ff00;}
a:active {text-decoration: none; color: #00ff00;}
a:hover {text-decoration: underline; color: #00ff00;}
</style>
<script type="text/javascript">

var bustcachevar=1 
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) 
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ 
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) 
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ 
if (file.indexOf(".js")!=-1){ 
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ 
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " 
}
}
}

</script>


</head>
<body class="body" marginwidth="0" marginheight="0" leftmargin="0" rightmargin="0" topmargin="0" background-color:"#000000" bottommargin="0">
&nbsp;<center>

<!-- Chat Updates -->

<img src="images/lbh.png">
<table width="811" height="200" style="background-image: url(images/green-grad.png); background-repeat: repeat-x;">


<td overflow="auto" align="center" valign="top" height="200">



<font size="4">Hookah Chat Updates 
3.0 (March 24 
2010)</font><p><font color="#FFFFFF">If you would like to see a help guide to 
the chat room </font>
<a style="text-decoration: underline; font-style: italic; font-weight: bold" href="http://www.hookahradio.com/v2/help/" target="_blank">
<font color="#0000FF">click me</font></a><font color="#FFFFFF">.</font></p>
<p align="left"><font color="#FFFFFF">1. Gave the chat message window a new 
look.</font></p>
<p align="left"><font color="#FFFFFF">2. There is now a box below chat showing 
who&#39;s in chat. This will hold the HTML tags. -- BETA -- this will appear/dissapear/work/not work -- as I test things.</font></p>
<p align="left"><font color="#FFFFFF">3. The next set of updates will include:</font></p>
<ul>
	<li>
	<p align="left"><font color="#FFFFFF">HTML Chat Tags Restored (As long as 
	performance does not drop during this trial run)</font></p></li>
	<li>
	<p align="left"><font color="#FFFFFF">More Smilies&#39; for the chat room.</font></p>
	</li>
	<li>
	<p align="left"><font color="#FFFFFF">New Login-Registration Page.</font></p>
	</li>
</ul>
</td>
</table>
<img src="images/lbb.png"><br>

<br><br>
<img src="images/lbh.png">
	<iframe id="loadpage" src="index.php" align="center" width="810" height="850" frameborder="0" scrolling="no" style="background-color: #000000;border: 1px solid #000000;">
  		<p>Your browser does not support iframes.</p>
	</iframe>
	
	
	
	
	

<br><br><br>



<script type="text/javascript">
ajaxpage('includes/who.php', 'rightcolumn') 
</script>

Open in new window

0
 
GawaiCommented:
did u try the second method ?

0
 
mimoserAuthor Commented:
The second method was the one I used, the others looked like they used links, unless I'm reading it wrong.

0
 
GawaiCommented:
it should be index.php not .html

ref comment id 28533767
0
 
mimoserAuthor Commented:
Sorry, I did not see that comment. My pgae has to be index.html, however my Apache is settup to render php from html. That's how I was able to include the

<?php include( 'includes/who.php' ); ?>

Since it seems with this method, the error is coming from the script,
<script>
setTimeOut(4500, "refreshWho()");
function refreshWho(){
$("#divWho").load("who.php", function(){setTimeOut(4500, "refreshWho()");});
}
</script>

Is it possable to write that in php?

0
 
HainKurtSr. System AnalystCommented:
u should add jquery

add this to your page

    <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
0
 
HainKurtConnect With a Mentor Sr. System AnalystCommented:
go to jQuery.com. grab the jQuery 1.4.2 put under your web site and include in your page to use functions like $()

<script>
setTimeOut(4500, "refreshWho()");
function refreshWho(){
$("#divWho").load("who.php", function(){setTimeOut(4500, "refreshWho()");});
}
</script>

needs jQuery...

and one more note...

<div id=divWho>
<?php include( 'includes/who.php' ); ?>
</div>

is not error, this is a part from php... when used like this, on first load we will see some content and after 45 sec, it will be refreshed by jQuery... we may leave this empty like

<div id=divWho></div>

and refresh it on page load + reschedule it after 45 seconds...
0
 
mimoserAuthor Commented:
I have downloaded and added JQuery, linked it to my page, but I still do not see any DIV. Below is my index.html file.
<html> 
<head>
<meta http-equiv="X-UA-Compatible" content="IE=7"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
.body {
color: #00ff00;
font-family: Verdana, Arial;
font-size: 12px;
font-style: normal;
background-color: #000000;
}
a:link {text-decoration: none; color: #00ff00;}
a:visited {text-decoration: none; color: #00ff00;}
a:active {text-decoration: none; color: #00ff00;}
a:hover {text-decoration: underline; color: #00ff00;}
</style>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script> 
setTimeOut(4500, "refreshWho()"); 
function refreshWho(){ 
$("#divWho").load("includes/who.php", function(){setTimeOut(4500, "refreshWho()");}); 
} 
</script> 
</head>
<body class="body" marginwidth="0" marginheight="0" leftmargin="0" rightmargin="0" topmargin="0" background-color:"#000000" bottommargin="0">
&nbsp;<center>
<br><br>
<img src="images/lbh.png">
<iframe id="loadpage" src="index.php" align="center" width="810" height="850" frameborder="0" scrolling="no" style="background-color: #000000;border: 1px solid #000000;">
<p>Your browser does not support iframes.</p>
</iframe>
<br><br><br>
<div id=divWho></div>
</center><br><br>
</body>
</html>

Open in new window

0
 
mimoserAuthor Commented:
When I run that page, I get the following error --
Message: Object expected
Line: 21
Char: 1
Code: 0


Which is this line --

setTimeOut(4500, "refreshWho()");
0
 
HainKurtSr. System AnalystCommented:
use

setTimeOut(4500, "refreshWho()");
-->
var t=setTimeout("refreshWho()",45000);

sorry, I did not test it before ;)
0
 
mimoserAuthor Commented:
I could not get the DIV to show unless I put

<div id=divWho>
<?php include( 'includes/who.php' ); ?>
</div>

It worked for a minute, then stoped working in IE and FireFox.
IE also, was cacheing the style sheet. Any ideas?
0
 
mimoserAuthor Commented:
Thank you very much, I got it working!!
0
All Courses

From novice to tech pro — start learning today.