Jump to content

Archived

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

Aravinthan

Reading a text file

Recommended Posts

$Chunks = ceil(count($all_players_data / $MaxChunk));

should be

$Chunks = ceil(count($all_players_data)/ $MaxChunk);

Share this post


Link to post
Share on other sites

add

foreach($chunk_all_players_data as $chunk_players_data)
{
sleep(5); //ADD this will pause the script for 5 seconds (giving MySQL a rest)

Share this post


Link to post
Share on other sites

Man what is with me and bad news?  :confused:

 

 

Anyways, I tought it did well, until I saw that there was 4 datas missing. Yeah, there is supossed to be 3500 and there is only 3496.

 

And it is not at the end, but somewhere in the middle. I managed to find, where one of data has not been inserted.

 

THe data, with id 2476 has been inserted.

But the datas 2477, has been skipped... And it inserted the player 2478 instead...

 

 

Any idea why?

 

Thanks for your help,

 

And sorry for keep closing and re-opening this thread,

Ara

Share this post


Link to post
Share on other sites

And I also found out what case it didnt enter.

Line 11: goal_streak, point_streak, total_gp, suspended_games, training, weight, height, status_in_organisanization.

-32 -5  32  0  1  195  8  4 

But the -5, doesnt get inserted into the point_streak, instead, its the the 32 which takes his place.....

 

So everything else just snowballs from there....

Share this post


Link to post
Share on other sites

AHHHHHH...

 

I know why,

because as you see, we split it be 2 spaces:

 

 

But here:

-32 -5

Only 1....

Is there a way to fix this? Because there might be other players who have the same problem....

Share this post


Link to post
Share on other sites

OK si I change:

$field_data = explode('  ', $line_data);

 

To:

$line_data = str_replace(' ','  ',$line_data);
$line_data = str_replace('    ','  ',$line_data);
$field_data = explode('  ', $line_data);

 

But the first data of each line seems to not be inserting....

Share this post


Link to post
Share on other sites

OK si I change:

$field_data = explode('  ', $line_data);

 

To:

$line_data = str_replace(' ','  ',$line_data);
$line_data = str_replace('    ','  ',$line_data);
$field_data = explode('  ', $line_data);

But the first data of each line seems to not be inserting....

 

Use this instead:

            $line_data = str_replace(' -', '  -', $line_data);
            $field_data = explode('  ', $line_data);

Share this post


Link to post
Share on other sites

Hi,

The data seems to be well inserted,

But there is still 4 players in the middle that doesnt get inserted.

The 2476 gets inserted, but not the 2477....

And it inserts the 2478 right after 2476....

Share this post


Link to post
Share on other sites

OK I searched the DB, and his id is 902...

 

Doesnt make any sens.

 

I put a id field, with an auto_incriment feautre.... So it is supposed to go one by one.....

 

Any idea why it might be messing up?

 

 

EDIT:

 

I think I might know why, there is 3 or 4 Sean Collins, but like the code Updates, when there is already one, it doesnt insert the other ones....

Man this is annoying.... Any way to work around it?

Share this post


Link to post
Share on other sites

There are duplicate entries in player.txt

 

You have three entries for Sean Collins, and two entries for Adam Courchaine and for Trevor Lewis. This is why it skips some entries.

Share this post


Link to post
Share on other sites

After inserting 2476,

It sends out:

Cannot inset/update table!You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 19

 

This error....

Share this post


Link to post
Share on other sites

Ignore the post I made earlier. I messed up. Undo the changes I told you to do.

Share this post


Link to post
Share on other sites

Ok fixed my mistake now. First drop your existing players table. I have modified the table.

 

Replace this line

(`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY,

 

With

(`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`player_id` VARCHAR( 32 ) NOT NULL,

 

Change

foreach($chunk_all_players_data as $chunk_players_data)

To

$row_id = 1;
foreach($chunk_all_players_data as $chunk_players_data)

 

Now change

    // check to see if the player already exist
    $player_name = sql_safe($player_data[13]);
    $user_exists_sql = "SELECT `name` FROM `$player_table_name` WHERE `name`=$player_name ";
    $result = mysql_query($user_exists_sql) or die('Error checking user!<br />'.mysql_error());

    // if the user does not exist, use an INSERT STATEMENT
    // we'll add the user into the database
    if(mysql_num_rows($result) == '0')
       {
           $sql = "INSERT INTO `$player_table_name` SET ";
           $update_user = false;
       }

to

        // check to see if the player already exist
        $player_id = md5($player_data[13] . $row_id++);

        $user_exists_sql = "SELECT `player_id` FROM `$player_table_name` WHERE `player_id`='$player_id'";
        $result = mysql_query($user_exists_sql) or die('Error checking user!<br />'.mysql_error());

        // if the user does not exist, use an INSERT STATEMENT
        // we'll add the user into the database
        if(mysql_num_rows($result) == 0)
        {
               $sql = "INSERT INTO `$player_table_name` SET `player_id`='$player_id', ";
               $update_user = false;
        }

 

All 3500 records should get inserted.

 

 

Share this post


Link to post
Share on other sites

×

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.