mimoser
asked on
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?
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">
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
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
the other option is jQuery (not tested may have syntax error ;)
<script>
setTimeOut(4500, "refreshWho()");
function refreshWho(){
$("#divWho").load("who_who le.php", function(){setTimeOut(4500 , "refreshWho()");});
}
</script>
<div id=divWho>
<?php include( 'includes/who.php' ); ?>
</div>
<script>
setTimeOut(4500, "refreshWho()");
function refreshWho(){
$("#divWho").load("who_who
}
</script>
<div id=divWho>
<?php include( 'includes/who.php' ); ?>
</div>
ASKER
Those solutions are using IFRAMES is there a way to skip IFRAME, maybe with a simple AJAX solution?
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
<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
ASKER
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?
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
}
</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?
In your who.php put this code on top
<meta http-equiv="refresh" content="45;URL=http://www.yoursite.com/who.php">
<meta http-equiv="refresh" content="45;URL=http://www.yoursite.com/who.php">
ASKER
That is, however the entire DIV is not showing up.
post your complete code pls
ASKER
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">
<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>
try with this one.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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(co ntainerid) .innerHTML =page_requ est.respon seText
document.getElementById(co
<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">
<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'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' 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>
did u try the second method ?
ASKER
The second method was the one I used, the others looked like they used links, unless I'm reading it wrong.
it should be index.php not .html
ref comment id 28533767
ref comment id 28533767
ASKER
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?
<?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
}
</script>
Is it possable to write that in php?
u should add jquery
add this to your page
<script type="text/javascript" src="js/jquery-1.4.2.min.j s"></scrip t>
add this to your page
<script type="text/javascript" src="js/jquery-1.4.2.min.j
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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">
<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>
ASKER
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()");
Message: Object expected
Line: 21
Char: 1
Code: 0
Which is this line --
setTimeOut(4500, "refreshWho()");
use
setTimeOut(4500, "refreshWho()");
-->
var t=setTimeout("refreshWho() ",45000);
sorry, I did not test it before ;)
setTimeOut(4500, "refreshWho()");
-->
var t=setTimeout("refreshWho()
sorry, I did not test it before ;)
ASKER
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?
<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?
ASKER
Thank you very much, I got it working!!
https://www.experts-exchange.com/questions/22858847/Meta-Refresh-a-Div-section-only-Not-the-entire-page.html