JChilds Posted July 21, 2008 Share Posted July 21, 2008 I have the following code that downloads the data from an online game and inserts it into a table. It deletes all entries older than 72 hours, and optimizes the table also. My problem is, that it will quite happily do this for the first loop , but it stops after then (only does the first server) I have No idea at all why this is happening... Can anyone please help me? mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select db"); $timestamp = date("Y-m-d H:i:s", mktime(date("H")+6, date("i"), date("s"), date("m") , date("d"), date("Y"))); $old = date("Y-m-d H:i:s", mktime(date("H")-66, date("i"), date("s"), date("m") , date("d"), date("Y"))); $server = 'game.net' ; $serverw = 'en' ; for ( $x = 1; $x <= 22; $x += 1) { $x = $x+1; $world = $serverw.$x ; mysql_query("DELETE FROM $world WHERE timestamp < '$old'"); $lines = gzfile('http://'.$world.'.'.$server.'/map/data.txt.gz'); if(!is_array($lines)) die("File could not be opened"); foreach($lines as $line) { list($id, $name,$x, $y, $tribe, $points, $rank) = explode(',', $line); $name = urldecode($name); $name = addslashes($name); mysql_query("INSERT INTO $world SET timestamp='$timestamp', id='$id', name='$name', x='$x', y='$y', tribe='$tribe', points='$points', rank='$rank'"); } $sql = 'OPTIMIZE TABLE `$world`'; mysql_query($sql); echo mysql_error(); } Link to comment https://forums.phpfreaks.com/topic/115765-solved-for-loop-wont-work-with-this-mysql-query/ Share on other sites More sharing options...
jonsjava Posted July 21, 2008 Share Posted July 21, 2008 I'm bigger about while loops: <?php mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select db"); $timestamp = date("Y-m-d H:i:s", mktime(date("H")+6, date("i"), date("s"), date("m") , date("d"), date("Y"))); $old = date("Y-m-d H:i:s", mktime(date("H")-66, date("i"), date("s"), date("m") , date("d"), date("Y"))); $server = 'game.net' ; $serverw = 'en' ; $count = 1; while ($count <23){ $world = $serverw.$count; mysql_query("DELETE FROM $world WHERE timestamp < '$old'"); $lines = gzfile('http://'.$world.'.'.$server.'/map/data.txt.gz'); if(!is_array($lines)) die("File could not be opened"); foreach($lines as $line) { list($id, $name,$x, $y, $tribe, $points, $rank) = explode(',', $line); $name = urldecode($name); $name = addslashes($name); mysql_query("INSERT INTO $world SET timestamp='$timestamp', id='$id', name='$name', x='$x', y='$y', tribe='$tribe', points='$points', rank='$rank'"); } $sql = 'OPTIMIZE TABLE `$world`'; mysql_query($sql); echo mysql_error(); $count++; } Link to comment https://forums.phpfreaks.com/topic/115765-solved-for-loop-wont-work-with-this-mysql-query/#findComment-595145 Share on other sites More sharing options...
JChilds Posted July 21, 2008 Author Share Posted July 21, 2008 Worked perfectly! Thankyou! Link to comment https://forums.phpfreaks.com/topic/115765-solved-for-loop-wont-work-with-this-mysql-query/#findComment-595157 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.