"; } $query = "SELECT name, plays FROM currentmaps"; $result = mysql_query($query); //Go through the current map cycle, to check for maps over the limit. while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row['plays'] >= 1) { //If over the limit, copy to disabled, delete from current mysql_query("DELETE FROM currentmaps WHERE name = '$row[name]'"); mysql_query("INSERT INTO disabledmaps (name) VALUES ('$row[name]')"); echo $row['name'] . " IS OVER!!"; } } //Time to check the current map list, and make sure it has atleast 10 maps. If not, then grab one at random from the disabled list. $query = "SELECT name, COUNT(name) FROM currentmaps GROUP BY name"; $result = mysql_query($query) or die(mysql_error()); //count the rows while($row = mysql_fetch_array($result)){ $a = $a +1; } //Check if the count is less than 10, if so, grab a map from disabled if ($a < 4) { $result = mysql_query("select name from disabledmaps order by rand() limit 1"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { mysql_query("DELETE FROM disabledmaps WHERE name = '$row[name]'"); mysql_query("INSERT INTO currentmaps (name) VALUES ('$row[name]')"); } } //Ok, now that the database is fully updated, and stripped of maps that have gone over, lets write to the mapcycle. $myFile = "mapcycle.txt"; //Do the query, and start the loop to append to the now empty file. $query = "SELECT name, plays FROM currentmaps"; $result = mysql_query($query); $fh = fopen($myFile, 'w') or die("can't open file"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $stringData = "$row[name]\n"; fwrite($fh, $stringData); } fclose($fh); ?>