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. Link to comment https://forums.phpfreaks.com/topic/139331-php-query-auto-refresh-using-ajax/ 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 Link to comment https://forums.phpfreaks.com/topic/139331-php-query-auto-refresh-using-ajax/#findComment-729231 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.) Link to comment https://forums.phpfreaks.com/topic/139331-php-query-auto-refresh-using-ajax/#findComment-729537 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? Link to comment https://forums.phpfreaks.com/topic/139331-php-query-auto-refresh-using-ajax/#findComment-729541 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. Link to comment https://forums.phpfreaks.com/topic/139331-php-query-auto-refresh-using-ajax/#findComment-729546 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.