How can I run a file (mysql query loop) without the need to load a page. Is the only way by using a cronjob or is there any alternative solution. Solutions I tried so far: 1) Keeping the php file open and auto reload it every 10 minutes. 2) Using an ajax to load the page while the user is on the page. The problem is; The query is looped, it requires time to complete. How can this be established without the need to persist on reloading the page. Codes:
<meta http-equiv="refresh" content="600" >
<?php
include("./includes/connect.php");
$i = 1;
$numberOfRows = mysql_query('SELECT COUNT(`id`) FROM table_name');
$scoreboardquery = mysql_query("SELECT * FROM table_name ORDER BY points DESC");
while(($row = mysql_fetch_assoc($scoreboardquery)) || $i<=$numberOfRows){
$scoreid = $row['id'];
$mysql_qeury = mysql_query("UPDATE table_name SET scoreboard_rank = '$i' WHERE id = '$scoreid'");
$i++;
}
if($mysql_qeury){
echo "Done!";
}else
echo "Not Done";
?>
To give a clear idea about what I am trying to do. I am trying to give users a rank (1st, 2nd, 3rd) based on descending order of their points. So on the fly, if there any solution to implement what I am trying to do, better, please come forward.