Jump to content

Recommended Posts

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();
}

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++;
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.