Jump to content

Reading a text file


Aravinthan

Recommended Posts

  • Replies 100
  • Created
  • Last Reply

Top Posters In This Topic

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

Link to comment
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....

Link to comment
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....

Link to comment
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);

Link to comment
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?

Link to comment
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.

 

 

Link to comment
Share on other sites

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.