Jump to content

[SOLVED] progress meter


chriscloyd

Recommended Posts

I have this script that updates teams ranks and what not i had 200 teams and it took forever to load the page

is there a way i can add a progress script to show how long it will take?

 

http://www.chaoslegionclan.net/cegl/files/admin_updateranks.php?division_id=1&confrence_id=1

Link to comment
https://forums.phpfreaks.com/topic/48659-solved-progress-meter/
Share on other sites

Why don't you just implement the script as a cron job?

 

Then you don't have to log in as the admin and waste your time waiting for the script to finish.  Even if you implement a progress bar, eventually you will reach a point where there are so many teams that the script takes longer than your webserver's timeout period.

Link to comment
https://forums.phpfreaks.com/topic/48659-solved-progress-meter/#findComment-238381
Share on other sites

the script is really easy

 

<?php
include("config.php");
$get_Teams = mysql_query("SELECT * FROM teams WHERE division_id = '".$_GET['division_id']."' AND team_confrence = '".$_GET['confrence_id']."' ORDER by `team_wins` DESC, `team_loses` ASC, `team_ties` ASC, `team_roundw` DESC, `team_roundl` ASC, `team_forfeitw` ASC, `team_forfeitl` DESC") or die(mysql_error());
$rank = 0;
while ($team_rank = mysql_fetch_array($get_Teams)) {
$rank++;
$update_rank =  mysql_query("UPDATE teams SET team_rank = '".$rank."' WHERE team_id = '".$team_rank['team_id']."'");
if ($update_rank) {
	echo '-Updated Rank For Team '.$team_rank['team_name'].'  From '.$team_rank['team_rank'].' To '.$rank.'<br />';
} else {
	echo '-Could not update the rank for team '.$team_rank['team_name'].'<br />';
}
}
?>

 

I tried it with 700 teams and it didnt timeout

Link to comment
https://forums.phpfreaks.com/topic/48659-solved-progress-meter/#findComment-238383
Share on other sites

A couple of items:

 

You're not sanitizing your values before putting them in your query.

 

Why are you using 'SELECT * FROM' when the only values you're using in the loop are team_id, team_name, and team_rank?  If there are extra fields in the table, or if you add fields later, you are just pulling out extra data you'll never use.  'SELECT team_id, team_name, team_rank FROM' would be better IMO.

 

You could probably do this in one query with some form of UPDATE ... SELECT, although I'm not sure how exactly.

 

Lastly, just because the script is simple doesn't mean it's not suitable as a cron job.

Link to comment
https://forums.phpfreaks.com/topic/48659-solved-progress-meter/#findComment-238405
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.