PcGeniusProductions Posted January 3, 2009 Share Posted January 3, 2009 Hi Guys. I have a script that runs a query on a SQL Database and returns results. The results in question will be updated very frequently (every 5 seconds) and I need a way of auto-updating the results shown on the PHP Page. Here is my script... <?php $result1 = mysql_query("SELECT * FROM ajaxim_users", $openDB); $num_rows1 = mysql_num_rows($result1); ?> <?php $result2 = mysql_query("SELECT * FROM ajaxim_users WHERE is_online = 1 AND admin = 1", $openDB); $num_rows2 = mysql_num_rows($result2); ?> <?php $result3 = mysql_query("SELECT * FROM ajaxim_users WHERE is_online = 1 AND admin = 0", $openDB); $num_rows3 = mysql_num_rows($result3); ?> <?php $result4 = mysql_query("SELECT * FROM ajaxim_users WHERE banned = 1", $openDB); $num_rows4 = mysql_num_rows($result4); ?> <?php $result5 = mysql_query("SELECT * FROM ajaxim_chats", $openDB); $num_rows5 = mysql_num_rows($result5); ?> <strong>Members:</strong><br /><?echo"$num_rows1";?><hr /> <strong>Online Admins:</strong><br /><?echo"$num_rows2";?><hr /> <strong>Online Users:</strong><br /><?echo"$num_rows3";?><hr /> <strong>Banned Users:</strong><br /><?echo"$num_rows4";?><hr /> <strong>Chatrooms:</strong><br /><?echo"$num_rows5";?><hr /> I have tried for days to find a script that works. And not only do none of the google-found scripts not work, they are unreasonably long. All I want to do is auto-refresh the above script every 10 seconds. I will be grateful for any help you can offer. Quote Link to comment Share on other sites More sharing options...
priti Posted January 4, 2009 Share Posted January 4, 2009 Can you do it with meta tag in <head> add <META HTTP-EQUIV=Refresh CONTENT='100; URL=index.php'> give time in seconds here it is 100 and the url of file to refresh. We used this way to refresh teh existing admin script to get the new records on our pages . Thanks Quote Link to comment Share on other sites More sharing options...
xtopolis Posted January 4, 2009 Share Posted January 4, 2009 You can also use setTimeout(). Also, your first 4 queries can probably be combined to make the process more efficient. (Creating 5 queries creates extra overhead.) Also, you should not be selecting * especially if you are only looking for the num_rows. (Selecting more columns that you are using creates extra overhead.) Quote Link to comment Share on other sites More sharing options...
Zeradin Posted January 4, 2009 Share Posted January 4, 2009 What if the Can you do it with meta tag in <head> add <META HTTP-EQUIV=Refresh CONTENT='100; URL=index.php'> give time in seconds here it is 100 and the url of file to refresh. We used this way to refresh teh existing admin script to get the new records on our pages . Thanks what if the file is an include in a div that has a header can you refresh the content of just the div? Quote Link to comment Share on other sites More sharing options...
xtopolis Posted January 4, 2009 Share Posted January 4, 2009 @Zeradin The <meta> tag will refresh the whole page. Using javascript you could use a setTimeout function to query and overwrite the div's content with new data, leaving the other parts of the page intact. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.