dwlerwill
Technical User
- May 25, 2001
- 329
Hi guys
I have a page that auto refreshes every 5 seconds to display any new data in the database however when the refresh happens it overwrites what the user has/is typing in a textbox. Is it possible to refresh part of the page IE the mysql query and the php chunk that displays the data.
The refresh is in java which is why i'm confused as I don't know much about that.
Here is what I have
<?
include 'connect.php';
session_start();
?><head>
<script>
<!--
/*
Auto Refresh Page with Time script
By JavaScript Kit (javascriptkit.com)
Over 200+ free scripts here!
*/
//enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59
var limit="0:10"
if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function beginrefresh(){
if (!document.images)
return
if (parselimit==1)
window.location.reload()
else{
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
else
curtime=cursec+" seconds left until page refresh!"
window.status=curtime
setTimeout("beginrefresh()",1000)
}
}
window.onload=beginrefresh
//-->
</script>
<?
if (isset($_SESSION['character_name']))
{
$player=$_SESSION['character_name'];
$userstats="SELECT * from users where character_name='$character_name'";
$userstats2=mysql_query($userstats) or die("Could not get user stats");
$userstats3=mysql_fetch_array($userstats2);
if($submit)
{
$time=date("h:ia d/j/y");
$name=$player;
$result=MYSQL_QUERY("INSERT INTO chattext (id,name,message,time)".
"VALUES ('NULL','$name', '$message','$time')");
}
?>
<?
$result = mysql_query("select * from chattext order by id desc limit 15");
//the while loop
while($r=mysql_fetch_array($result))
{
//getting each variable from the table
$time=$r["time"];
$id=$r["id"];
$message=$r["message"];
$name=$r["name"];
?>
<? echo $name ?>
<? echo $message ?>
<br>
<? } ?>
<form action="<? echo $php_self ?>" method="post">
<INPUT TYPE='TEXT' value='message' NAME='message' SIZE=30 maxlength='100'>
<input type="submit" name="submit" value="submit">
</form>
<?
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
}
?>
</head>
any comments or suggestions would be welcome
David Lerwill
"If at first you don't succeed go to the pub"
I have a page that auto refreshes every 5 seconds to display any new data in the database however when the refresh happens it overwrites what the user has/is typing in a textbox. Is it possible to refresh part of the page IE the mysql query and the php chunk that displays the data.
The refresh is in java which is why i'm confused as I don't know much about that.
Here is what I have
<?
include 'connect.php';
session_start();
?><head>
<script>
<!--
/*
Auto Refresh Page with Time script
By JavaScript Kit (javascriptkit.com)
Over 200+ free scripts here!
*/
//enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59
var limit="0:10"
if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function beginrefresh(){
if (!document.images)
return
if (parselimit==1)
window.location.reload()
else{
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
else
curtime=cursec+" seconds left until page refresh!"
window.status=curtime
setTimeout("beginrefresh()",1000)
}
}
window.onload=beginrefresh
//-->
</script>
<?
if (isset($_SESSION['character_name']))
{
$player=$_SESSION['character_name'];
$userstats="SELECT * from users where character_name='$character_name'";
$userstats2=mysql_query($userstats) or die("Could not get user stats");
$userstats3=mysql_fetch_array($userstats2);
if($submit)
{
$time=date("h:ia d/j/y");
$name=$player;
$result=MYSQL_QUERY("INSERT INTO chattext (id,name,message,time)".
"VALUES ('NULL','$name', '$message','$time')");
}
?>
<?
$result = mysql_query("select * from chattext order by id desc limit 15");
//the while loop
while($r=mysql_fetch_array($result))
{
//getting each variable from the table
$time=$r["time"];
$id=$r["id"];
$message=$r["message"];
$name=$r["name"];
?>
<? echo $name ?>
<? echo $message ?>
<br>
<? } ?>
<form action="<? echo $php_self ?>" method="post">
<INPUT TYPE='TEXT' value='message' NAME='message' SIZE=30 maxlength='100'>
<input type="submit" name="submit" value="submit">
</form>
<?
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
}
?>
</head>
any comments or suggestions would be welcome
David Lerwill
"If at first you don't succeed go to the pub"