Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

autorefresh problem 1

Status
Not open for further replies.

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
&quot;If at first you don't succeed go to the pub&quot;
 
I was just wondering if I could add a bit of php code to the connection string to just refresh that, that way i could take all the java out (as I hate java :p )

David Lerwill
&quot;If at first you don't succeed go to the pub&quot;
 
PHP runs on the server, not the client, so PHP is incapable of refreshing part of a page from the server.

It is more than possible that a client-side scripting language can be used to drive a PHP script, fetching the PHP script's output and displaying it in-place in the middle of an existing document. AJAX is an example of this idea.



Want the best answers? Ask the best questions! TANSTAAFL!
 
will look in AJAX and see what I can do, thank you sleipnir214

David Lerwill
&quot;If at first you don't succeed go to the pub&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top