Jump to content

Aravinthan

Members
  • Posts

    162
  • Joined

  • Last visited

    Never

Posts posted by Aravinthan

  1. To clarify the parts highlighted in red

    63  61  54  61  63  60  63  70  66  63

    63  71  68  61  115  42  10  0  1  4  1

    1973  24  6  950000  0  1991  4  17  98

    0  0  0  0

    0  0  0

    179000  3000  908  0  0  0

    1  0  0  0  0  0

    0  0  0  0  0  0  0  0  0  0

    0  0  0  0  0  0  0  0  0  0

    0  0  0  0  0  0  0  0  0  0

    0  0  0  0  4  194  7  3

    0  0  0  0  0

    -

    Milan Hnilicka

     

    drafted

    150080070070075095144103068062125080125

    1.16 (24.3.2002)

    1.16 (24.3.2002)

    0  0  98  65  70

    Do not match up to a field in the database. Is this correct? All the other bits are inserted into the database fine.

     

    For the 98,

     

    It is supossed to be under colum rights, and I think thats ok.

     

    But the 3 others, should be under:

    month_ goals, month_assists, month_gwg

     

    Iam guessing, thats because there is no week_games and month_games

  2. You are right, there is 2 Things that are missing.

    Line 4, it is supossed to be:

    week_games, week_goals, week_assists, week_points

     

    Forgot the week_games... so sorry.

     

    And line 5:

    month_games, month_goals, month_assists, month_points

     

    Again forgot a colum games....

     

    I am so sorry, and I also forgot to mention this:

     

    Is it possible to add a colum age?

     

    After, overral_draft(last data), where it takes a date in another table and it subtracts it to give is age?

     

    OA =

    (shooting + playmaking + stickhandling + checking + hitting + marking + skating + endurance + penalty + faceoff + leadership + strength + potentiel + consistency + gree) / 15

     

    OFF =

    (shooting + playmaking + stickhandling) / 3

     

    DEF =

    DEF = (checking + marking + hitting) / 3

     

     

    All 4 after the other ones....

     

     

    Thanks for your help,

    Ara

    And there is 3 other stuffs:

     

  3. OK I fell really dumb....

     

    Forgot to execute my code lol....

     

    Added this:

    $create_table = mysql_query($make_table) or die(mysql_error());
    

     

    And it gives this error:

    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 77

     

    Line 77:

    
    `total_gp` INT(5) NOT NULL,
    

     

     

    Cant see any errors there...

  4. Changed it, but same response...

     

    Code:

    <?php
    
    function sql_safe($value)
    {
        $value = trim($value);
    
        if(is_numeric($value))
            return $value;
        else
            return "'$value'";
    }
    
    // DONT FORGET TO CONNECT TO MYSQL!
    $conn = mysql_connect('localhost', 'liguehs_ara', '1992arayugi');
    mysql_select_db('liguehs_league');
    
    $player_table_name = 'players';
    
    $check="SELECT * FROM $player_table_name";
    
    $result=@mysql_query($check);
    
    if (!$result){
    $make_table = 'CREATE TABLE IF NOT EXISTS  `liguehs_league`.`players`
    (`id` INT( 11 ) NOT NULL AUTO_INCREMENT,
    `shooting` INT(5) NOT NULL,
    `playmaking` INT(5) NOT NULL,
    `stickhandling` INT(5) NOT NULL,
    `checking` INT(5) NOT NULL,
    `marking` INT(5) NOT NULL,
    `hitting` INT(5) NOT NULL,
    `skating` INT(5) NOT NULL,
    `endurance` INT(5) NOT NULL,
    `penalty` INT(5) NOT NULL,
    `faceoffs` INT(5) NOT NULL,
    `leadership` INT(5) NOT NULL,
    `strength` INT(5) NOT NULL,
    `potentiel` INT(5) NOT NULL,
    `consistency` INT(5) NOT NULL,
    `greed` INT(5) NOT NULL,
    `fighting` INT(5) NOT NULL,
    `click` INT(5) NOT NULL,
    `team` INT(5) NOT NULL,
    `main_position` INT(5) NOT NULL,
    `country` INT(5) NOT NULL,
    `birth_year` INT(5) NOT NULL,
    `birth_day` INT(5) NOT NULL,
    `birth_month` INT(5) NOT NULL,
    `salary` INT(11) NOT NULL,
    `contract_lenght` INT(5) NOT NULL,
    `draft_year` INT(5) NOT NULL,
    `draft_round` INT(5) NOT NULL,
    `drafted_by` INT(5) NOT NULL,
    `rights` INT(5) NOT NULL,
    `week_goals` INT(5) NOT NULL,
    `week_assists` INT(5) NOT NULL,
    `month_goals` INT(5) NOT NULL,
    `month_assists` INT(5) NOT NULL,
    `month_gwg` INT(5) NOT NULL,
    `record_goals` INT(5) NOT NULL,
    `record_assists` INT(5) NOT NULL,
    `record_points` INT(5) NOT NULL,
    `no_trade_switch` INT(5) NOT NULL,
    `two-way_switch` INT(5) NOT NULL,
    `player-team_option` INT(5) NOT NULL,
    `status` INT(5) NOT NULL,
    `rookie` INT(5) NOT NULL,
    `rconsidering_offer_data` INT(11) NOT NULL,
    `team_offering` INT(5) NOT NULL,
    `amount_time_spent_considering` INT(5) NOT NULL,
    `injury` INT(5) NOT NULL,
    `line8` INT(5) NOT NULL,
    `line9` INT(5) NOT NULL,
    `line10` INT(5) NOT NULL,
    `goal_streak` INT(5) NOT NULL,
    `point_streak` INT(5) NOT NULL,
    `total_gp` INT(5) NOT NULL,
    `point_streak` INT(5) NOT NULL,
    `suspended_game` INT(5) NOT NULL,
    `training` INT(5) NOT NULL,
    `weight` INT(5) NOT NULL,
    `height` INT(5) NOT NULL,
    `status_in_organization` INT(5) NOT NULL,
    `best_streak_games` INT(5) NOT NULL,
    `best_streak_gwg` INT(5) NOT NULL,
    `best_streak_assists` INT(5) NOT NULL,
    `best_streak_points` INT(5) NOT NULL,
    `best_streak_goals` INT(5) NOT NULL,
    `line13` INT(5) NOT NULL,
    `name` VARCHAR(100) NOT NULL,
    `line15` INT(5) NOT NULL,
    `drafted` VARCHAR(100) NOT NULL,
    `line17` INT(5) NOT NULL,
    `line18` INT(5) NOT NULL,
    `line19` INT(5) NOT NULL,
    `attitude` INT(5) NOT NULL,
    `alternate_position` INT(5) NOT NULL,
    `nhl_rights` INT(5) NOT NULL,
    `injury_prone` INT(5) NOT NULL,
    `overral_draft INT(5) NOT NULL)
    ENGINE = MyISAM';
    }
    
    $players_data_file = file('players.txt');
    
    // remove first line from file, this is line holds the number of players
    $total_players = array_shift($players_data_file);
    
    // DO NOT CHANGE THIS. THIS IS SET UP TO MATCH THE DATA IN THE DATA.TXT FILE
    $fields = array( array('shooting', 'playmaking', 'stickhandling', 'checking', 'marking', 'hitting', 'skating', 'endurance', 'penalty', 'faceoffs'),
                     array('leadership', 'strength', 'potentiel', 'consistency', 'greed', 'fighting', 'click', 'team', 'main_position', 'country', 'handed'),
                     array('birth_year', 'birth_day', 'birth_month', 'salary', 'contract_lenght', 'draft_year', 'draft_round', 'drafted_by', 'rights'),
                     array('week_goals', 'week_assists', 'week_gwg', 'month_goals'),
                     array('month_assists', 'month_gwg'),
                     array('record_goals', 'record_assists', 'record_points', 'no_trade_switch', 'two-way_switch', 'player-team_option'),
                     array('status', 'rookie', 'considering_offer_data', 'team_offering', 'amount_time_spent_considering', 'injury'),
                     array('line8'),
                     array('line9'),
                     array('line10'),
                     array('goal_streak', 'point_streak', 'total_gp', 'suspended_game', 'training', 'weight', 'height', 'status_in_organization'),
                     array('best_streak_games', 'best_streak_gwg', 'best_streak_assists', 'best_streak_points', 'best_streak_goals'),
                     array('line13'),
                     array('name'),
                     array('line15'),
                     array('drafeted'),
                     array('line17'),
                     array('line18'),
                     array('line19'),
                     array('attitude', 'alternate_position', 'nhl_rights', 'injury_prone', 'overral_draft')
                    );
    
    // split every 20 lines into a new array
    $all_players_data = array_chunk($players_data_file, 20);
    
    // loop through each block of 20 lines
    foreach($all_players_data as $player_data)
    {
    // 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);
    
        // 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;
        }
        // user does exist so we'll use an UPDATE statement
        // update the existing user
        else
        {
            $sql = "UPDATE `$player_table_name` ";
            $update_user = true;
        }
        // here we're looping through each line
        foreach($player_data as $line_key => $line_data)
        {
            // if we're not on line 8, 9, 10, 13, 14 or 15
            // turn line data into an array
            if(!in_array($line_key, array(7, 8, 9, 12, 13, 14)))
            {
                $field_data = explode('  ', $line_data);
    
                // match up the data with the field array
                // this is where our query is generated
                foreach($field_data as $field_key => $field_value)
                {
                    if(isset($fields[$line_key][$field_key]))
                        $sql .= "`" . $fields[$line_key][$field_key] . "`=" . sql_safe($field_value) . ', ';
                }
    
                $sql .= "\n";
            }
    // add the whole line into the query
            else
            {
                // if we're updating the user skip line 14
                if( $update_user && $line_key == 13)
                    continue;
    
                $sql .= "`" . $fields[$line_key][0] . "`=" . sql_safe($line_data) . ", \n";
            }
    
        }
    
    // remove the last three characters from $sql
        $sql  = substr($sql, 0, -3);
    
        // add the WHERE clause only if we are updating the user
        if($update_user)
            $sql .= " WHERE name=$player_name";
    
        echo '<pre>' . print_r($sql, true) . '</pre>';
    
    
    }
    
    ?>
    

  5. Oh oups...

     

     

    But still same error....

    http://liguedhockeysimule.x10hosting.com/converter/test.php

     

    Code:

    <?php
    
    function sql_safe($value)
    {
        $value = trim($value);
    
        if(is_numeric($value))
            return $value;
        else
            return "'$value'";
    }
    
    // DONT FORGET TO CONNECT TO MYSQL!
    $conn = mysql_connect('localhost', 'liguehs_ara', '1992arayugi');
    mysql_select_db('liguehs_league');
    
    $player_table_name = 'players';
    
    $check="SELECT * FROM $player_table_name";
    
    $result=@mysql_query($check);
    
    if (!$result){
    $make_table = 'CREATE TABLE IF NOT EXISTS  `liguehs_league`.`players`
    (`id` INT( 11 ) NOT NULL AUTO_INCREMENT,
    `shooting` INT(5) NOT NULL,
    `playmaking` INT(5) NOT NULL,
    `stickhandling` INT(5) NOT NULL,
    `checking` INT(5) NOT NULL,
    `marking` INT(5) NOT NULL,
    `hitting` INT(5) NOT NULL,
    `skating` INT(5) NOT NULL,
    `endurance` INT(5) NOT NULL,
    `penalty` INT(5) NOT NULL,
    `faceoffs` INT(5) NOT NULL,
    `leadership` INT(5) NOT NULL,
    `strength` INT(5) NOT NULL,
    `potentiel` INT(5) NOT NULL,
    `consistency` INT(5) NOT NULL,
    `greed` INT(5) NOT NULL,
    `fighting` INT(5) NOT NULL,
    `click` INT(5) NOT NULL,
    `team` INT(5) NOT NULL,
    `main_position` INT(5) NOT NULL,
    `country` INT(5) NOT NULL,
    `birth_year` INT(5) NOT NULL,
    `birth_day` INT(5) NOT NULL,
    `birth_month` INT(5) NOT NULL,
    `salary` INT(11) NOT NULL,
    `contract_lenght` INT(5) NOT NULL,
    `draft_year` INT(5) NOT NULL,
    `draft_round` INT(5) NOT NULL,
    `drafted_by` INT(5) NOT NULL,
    `rights` INT(5) NOT NULL,
    `week_goals` INT(5) NOT NULL,
    `week_assists` INT(5) NOT NULL,
    `month_goals` INT(5) NOT NULL,
    `month_assists` INT(5) NOT NULL,
    `month_gwg` INT(5) NOT NULL,
    `record_goals` INT(5) NOT NULL,
    `record_assists` INT(5) NOT NULL,
    `record_points` INT(5) NOT NULL,
    `no_trade_switch` INT(5) NOT NULL,
    `two-way_switch` INT(5) NOT NULL,
    `player-team_option` INT(5) NOT NULL,
    `status` INT(5) NOT NULL,
    `rookie` INT(5) NOT NULL,
    `rconsidering_offer_data` INT(11) NOT NULL,
    `team_offering` INT(5) NOT NULL,
    `amount_time_spent_considering` INT(5) NOT NULL,
    `injury` INT(5) NOT NULL,
    `line8` INT(5) NOT NULL,
    `line9` INT(5) NOT NULL,
    `line10` INT(5) NOT NULL,
    `goal_streak` INT(5) NOT NULL,
    `point_streak` INT(5) NOT NULL,
    `total_gp` INT(5) NOT NULL,
    `point_streak` INT(5) NOT NULL,
    `suspended_game` INT(5) NOT NULL,
    `training` INT(5) NOT NULL,
    `weight` INT(5) NOT NULL,
    `height` INT(5) NOT NULL,
    `status_in_organization` INT(5) NOT NULL,
    `best_streak_games` INT(5) NOT NULL,
    `best_streak_gwg` INT(5) NOT NULL,
    `best_streak_assists` INT(5) NOT NULL,
    `best_streak_points` INT(5) NOT NULL,
    `best_streak_goals` INT(5) NOT NULL,
    `line13` INT(5) NOT NULL,
    `name` VARCHAR(100) NOT NULL,
    `line15` INT(5) NOT NULL,
    `drafted` VARCHAR(100) NOT NULL,
    `line17` INT(5) NOT NULL,
    `line18` INT(5) NOT NULL,
    `line19` INT(5) NOT NULL,
    `attitude` INT(5) NOT NULL,
    `alternate_position` INT(5) NOT NULL,
    `nhl_rights` INT(5) NOT NULL,
    `injury_prone` INT(5) NOT NULL,
    `overral_draft INT(5) NOT NULL)
    ENGINE = MyISAM';
    }
    
    $players_data_file = file('players.txt');
    
    // remove first line from file, this is line holds the number of players
    $total_players = array_shift($players_data_file);
    
    // DO NOT CHANGE THIS. THIS IS SET UP TO MATCH THE DATA IN THE DATA.TXT FILE
    $fields = array( array('shooting', 'playmaking', 'stickhandling', 'checking', 'marking', 'hitting', 'skating', 'endurance', 'penalty', 'faceoffs'),
                     array('leadership', 'strength', 'potentiel', 'consistency', 'greed', 'fighting', 'click', 'team', 'main_position', 'country', 'handed'),
                     array('birth_year', 'birth_day', 'birth_month', 'salary', 'contract_lenght', 'draft_year', 'draft_round', 'drafted_by', 'rights'),
                     array('week_goals', 'week_assists', 'week_gwg', 'month_goals'),
                     array('month_assists', 'month_gwg'),
                     array('record_goals', 'record_assists', 'record_points', 'no_trade_switch', 'two-way_switch', 'player-team_option'),
                     array('status', 'rookie', 'considering_offer_data', 'team_offering', 'amount_time_spent_considering', 'injury'),
                     array('line8'),
                     array('line9'),
                     array('line10'),
                     array('goal_streak', 'point_streak', 'total_gp', 'suspended_game', 'training', 'weight', 'height', 'status_in_organization'),
                     array('best_streak_games', 'best_streak_gwg', 'best_streak_assists', 'best_streak_points', 'best_streak_goals'),
                     array('line13'),
                     array('name'),
                     array('line15'),
                     array('drafeted'),
                     array('line17'),
                     array('line18'),
                     array('line19'),
                     array('attitude', 'alternate_position', 'nhl_rights', 'injury_prone', 'overral_draft')
                    );
    
    // split every 20 lines into a new array
    $all_players_data = array_chunk($players_data_file, 20);
    
    // loop through each block of 20 lines
    foreach($all_players_data as $player_data)
    {
    // 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);
    
        // 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;
        }
        // user does exist so we'll use an UPDATE statement
        // update the existing user
        else
        {
            $sql = 'UPDATE `$player_table_name` ';
            $update_user = true;
        }
    
        // here we're looping through each line
        foreach($player_data as $line_key => $line_data)
        {
            // if we're not on line 8, 9, 10, 13, 14 or 15
            // turn line data into an array
            if(!in_array($line_key, array(7, 8, 9, 12, 13, 14)))
            {
                $field_data = explode('  ', $line_data);
    
                // match up the data with the field array
                // this is where our query is generated
                foreach($field_data as $field_key => $field_value)
                {
                    if(isset($fields[$line_key][$field_key]))
                        $sql .= "`" . $fields[$line_key][$field_key] . "`=" . sql_safe($field_value) . ', ';
                }
    
                $sql .= "\n";
            }
    // add the whole line into the query
            else
            {
                // if we're updating the user skip line 14
                if( $update_user && $line_key == 13)
                    continue;
    
                $sql .= "`" . $fields[$line_key][0] . "`=" . sql_safe($line_data) . ", \n";
            }
    
        }
    
    // remove the last three characters from $sql
        $sql  = substr($sql, 0, -3);
    
        // add the WHERE clause only if we are updating the user
        if($update_user)
            $sql .= " WHERE name=$player_name";
    
        echo '<pre>' . print_r($sql, true) . '</pre>';
    
    
    }
    
    ?>
    

  6. Hi,

     

    Thansk for your help,

    so this is what I got:

    <?php
    
    function sql_safe($value)
    {
        $value = trim($value);
    
        if(is_numeric($value))
            return $value;
        else
            return "'$value'";
    }
    
    // DONT FORGET TO CONNECT TO MYSQL!
    $conn = mysql_connect('localhost', 'liguehs_ara', '1992arayugi');
    mysql_select_db('liguehs_league');
    
    $player_table_name = 'players';
    
    $check="SELECT * FROM $player_table_name";
    
    $result=@mysql_query($check);
    
    if (!$result){
    $make_table = 'CREATE TABLE IF NOT EXISTS  `liguehs_league`.`players`
    (`id` INT( 11 ) NOT NULL AUTO_INCREMENT,
    `shooting` INT(5) NOT NULL,
    `playmaking` INT(5) NOT NULL,
    `stickhandling` INT(5) NOT NULL,
    `checking` INT(5) NOT NULL,
    `marking` INT(5) NOT NULL,
    `hitting` INT(5) NOT NULL,
    `skating` INT(5) NOT NULL,
    `endurance` INT(5) NOT NULL,
    `penalty` INT(5) NOT NULL,
    `faceoffs` INT(5) NOT NULL,
    `leadership` INT(5) NOT NULL,
    `strength` INT(5) NOT NULL,
    `potentiel` INT(5) NOT NULL,
    `consistency` INT(5) NOT NULL,
    `greed` INT(5) NOT NULL,
    `fighting` INT(5) NOT NULL,
    `click` INT(5) NOT NULL,
    `team` INT(5) NOT NULL,
    `main_position` INT(5) NOT NULL,
    `country` INT(5) NOT NULL,
    `birth_year` INT(5) NOT NULL,
    `birth_day` INT(5) NOT NULL,
    `birth_month` INT(5) NOT NULL,
    `salary` INT(11) NOT NULL,
    `contract_lenght` INT(5) NOT NULL,
    `draft_year` INT(5) NOT NULL,
    `draft_round` INT(5) NOT NULL,
    `drafted_by` INT(5) NOT NULL,
    `rights` INT(5) NOT NULL,
    `week_goals` INT(5) NOT NULL,
    `week_assists` INT(5) NOT NULL,
    `month_goals` INT(5) NOT NULL,
    `month_assists` INT(5) NOT NULL,
    `month_gwg` INT(5) NOT NULL,
    `record_goals` INT(5) NOT NULL,
    `record_assists` INT(5) NOT NULL,
    `record_points` INT(5) NOT NULL,
    `no_trade_switch` INT(5) NOT NULL,
    `two-way_switch` INT(5) NOT NULL,
    `player-team_option` INT(5) NOT NULL,
    `status` INT(5) NOT NULL,
    `rookie` INT(5) NOT NULL,
    `rconsidering_offer_data` INT(11) NOT NULL,
    `team_offering` INT(5) NOT NULL,
    `amount_time_spent_considering` INT(5) NOT NULL,
    `injury` INT(5) NOT NULL,
    `line8` INT(5) NOT NULL,
    `line9` INT(5) NOT NULL,
    `line10` INT(5) NOT NULL,
    `goal_streak` INT(5) NOT NULL,
    `point_streak` INT(5) NOT NULL,
    `total_gp` INT(5) NOT NULL,
    `point_streak` INT(5) NOT NULL,
    `suspended_game` INT(5) NOT NULL,
    `training` INT(5) NOT NULL,
    `weight` INT(5) NOT NULL,
    `height` INT(5) NOT NULL,
    `status_in_organization` INT(5) NOT NULL,
    `best_streak_games` INT(5) NOT NULL,
    `best_streak_gwg` INT(5) NOT NULL,
    `best_streak_assists` INT(5) NOT NULL,
    `best_streak_points` INT(5) NOT NULL,
    `best_streak_goals` INT(5) NOT NULL,
    `line13` INT(5) NOT NULL,
    `name` VARCHAR(100) NOT NULL,
    `line15` INT(5) NOT NULL,
    `drafted` VARCHAR(100) NOT NULL,
    `line17` INT(5) NOT NULL,
    `line18` INT(5) NOT NULL,
    `line19` INT(5) NOT NULL,
    `attitude` INT(5) NOT NULL,
    `alternate_position` INT(5) NOT NULL,
    `nhl_rights` INT(5) NOT NULL,
    `injury_prone` INT(5) NOT NULL,
    `overral_draft INT(5) NOT NULL)
    ENGINE = MyISAM';
    }
    
    $players_data_file = file('players.txt');
    
    // remove first line from file, this is line holds the number of players
    $total_players = array_shift($players_data_file);
    
    // DO NOT CHANGE THIS. THIS IS SET UP TO MATCH THE DATA IN THE DATA.TXT FILE
    $fields = array( array('shooting', 'playmaking', 'stickhandling', 'checking', 'marking', 'hitting', 'skating', 'endurance', 'penalty', 'faceoffs'),
                     array('leadership', 'strength', 'potentiel', 'consistency', 'greed', 'fighting', 'click', 'team', 'main_position', 'country', 'handed'),
                     array('birth_year', 'birth_day', 'birth_month', 'salary', 'contract_lenght', 'draft_year', 'draft_round', 'drafted_by', 'rights'),
                     array('week_goals', 'week_assists', 'week_gwg', 'month_goals'),
                     array('month_assists', 'month_gwg'),
                     array('record_goals', 'record_assists', 'record_points', 'no_trade_switch', 'two-way_switch', 'player-team_option'),
                     array('status', 'rookie', 'considering_offer_data', 'team_offering', 'amount_time_spent_considering', 'injury'),
                     array('line8'),
                     array('line9'),
                     array('line10'),
                     array('goal_streak', 'point_streak', 'total_gp', 'suspended_game', 'training', 'weight', 'height', 'status_in_organization'),
                     array('best_streak_games', 'best_streak_gwg', 'best_streak_assists', 'best_streak_points', 'best_streak_goals'),
                     array('line13'),
                     array('name'),
                     array('line15'),
                     array('drafeted'),
                     array('line17'),
                     array('line18'),
                     array('line19'),
                     array('attitude', 'alternate_position', 'nhl_rights', 'injury_prone', 'overral_draft')
                    );
    
    // split every 20 lines into a new array
    $all_players_data = array_chunk($players_data_file, 20);
    
    // loop through each block of 20 lines
    foreach($all_players_data as $player_data)
    {
    // check to see if the player already exist
        $user_exists_sql = "SELECT `name` FROM `'.$player_table_name.'` WHERE `name`=$player_name";
        $result = mysql_query($user_exists_sql);
    
        // 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;
        }
        // user does exist so we'll use an UPDATE statement
        // update the existing user
        else
        {
            $sql = 'UPDATE `'.$player_table_name.'` ';
            $update_user = true;
        }
    
        // here we're looping through each line
        foreach($player_data as $line_key => $line_data)
        {
            // if we're not on line 8, 9, 10, 13, 14 or 15
            // turn line data into an array
            if(!in_array($line_key, array(7, 8, 9, 12, 13, 14)))
            {
                $field_data = explode('  ', $line_data);
    
                // match up the data with the field array
                // this is where our query is generated
                foreach($field_data as $field_key => $field_value)
                {
                    if(isset($fields[$line_key][$field_key]))
                        $sql .= "`" . $fields[$line_key][$field_key] . "`=" . sql_safe($field_value) . ', ';
                }
    
                $sql .= "\n";
            }
    // add the whole line into the query
            else
            {
                // if we're updating the user skip line 14
                if( $update_user && $line_key == 13)
                    continue;
    
                $sql .= "`" . $fields[$line_key][0] . "`=" . sql_safe($line_data) . ", \n";
            }
    
        }
    
    // remove the last three characters from $sql
        $sql  = substr($sql, 0, -3);
    
        // add the WHERE clause only if we are updating the user
        if($update_user)
            $sql .= " WHERE name=$player_name";
    
        echo '<pre>' . print_r($sql, true) . '</pre>';
    
    
    }
    
    ?>
    

     

    But I get this error:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/liguehs/public_html/converter/test.php on line 144

     

    http://liguedhockeysimule.x10hosting.com/converter/test.php

     

    Line 144:

    if(mysql_num_rows($result) == 0)
    

     

    Thanks for your help,

    Ara

  7. Wow, WildTeen,

     

    Thanks so much!!!

     

    And you too Mad!!!

     

    But Wild Teen, is it possible:

     

    If there is no value in the Table, instead of updating, it Inserts?

     

    And also, if there is no Table with that name it Creates the table?

     

    I am feeling kinda of lazy for creating each one by itself.... lol

     

    If its not possible, well thats not much of a problem.

     

     

    Thanks once again guys for your amazing help!!

     

  8. LOL, i was just typing an example (see above)

    for the numbers use

    $details['drafted']['num1'][0];
    $details['drafted']['num1'][1];
    $details['drafted']['num1'][2];

     

     

    EDIT:

    LOL you read my mind or something?  :confused: lol!!!

     

    Ok so the code would be:

    echo "INSERT INTO table SET (stuffs,stuffs,etc) VALUES ('{$details['num1'][0];}','{$details['num1'][1],etc}')";
    

     

    Right?

     

    WOW MAN thanks again, I cant thank you enough lol!

  9. Wow ok,

    Thanks but for exemple,

    The Line 1, there is 10 Datas in it.

     

    So do I do :

    echo "INSERT INTO table SET (stuffs,stuffs,etc) VALUES ('{$details['num1']}','{$details['num1']}')";
    

    I dont think thats right no?

     

    And for the Boolean, part THANKS!!!!

     

    That would help me alot during the processing of the data.

     

    Wow seriously, I never tought I would be able to finish this coding so fast!! Man seriously,!!! I am bemused by your talent  :o

     

    And so Grateful that you spent alot of time for me!!!!

     

     

  10. Hi ok so I added the 20 lines:

    <?php
    $lines = file('players.txt');
    
    //$myLine = getLine(1);
    //echo $myLine[0]." ".$myLine[1]."etc".$myLine[10]."<br>";
    
    function getLine($line)
    {
       global $lines;
       return explode(" ", trim(str_replace("  "," ",$lines[$line])));
    }
    
    
    //other extended option
    /*
    $player = getPlayer();
    echo $player['Name'];
    echo $player['num1'][0];
    echo $player['num1'][1];
    echo $player['num1'][2];
    */
    
    $tmpLine = 0;
    $player = 1;
    echo "<pre>";
    while($details = getPlayer($player)) //loop until false
    {
    var_dump($details); //dump data // change to echo data correctly
    $player++; //edit: oops need this line!
    }
    
    function getPlayer($player)
    {
    global $lines;
    $player--;
    $player = $player * 20;
    //Check first line
    if(empty($lines[$player+1])){
    	return false;
    }
    //Setup details
    $details = array();
    $details['num1'] = getLine($player+1);
    $details['num2'] = getLine($player+2);
    $details['num3'] = getLine($player+3);
    $details['num4'] = getLine($player+4);
    $details['num5'] = getLine($player+5);
    $details['num6'] = getLine($player+6);
    $details['num7'] = getLine($player+7);
    $details['num8'] = getLine($player+;
    $details['num9'] = getLine($player+9);
    $details['num10'] = getLine($player+10);
    $details['num11'] = getLine($player+11);
    $details['num12'] = getLine($player+12);
    $details['num13'] = getLine($player+13);
    $details['Name'] = $lines[$player+14]; //Milan Hnilicka
    $details['Blank'] = $lines[$player+15]; //?
    $details['drafted'] = $lines[$player+16]; //drafted
    $details['num17'] = getLine($player+17);
    $details['num18'] = getLine($player+18);
    $details['num19'] = getLine($player+19);
    $details['num20'] = getLine($player+20);
    return $details;
    }
    
    ?>
    

     

    And the output can be seen here:

    http://liguedhockeysimule.x10hosting.com/converter/texttosql.php

     

    It splits the data exactly how I want!!! Thanks so much.

     

    But I cant figure out how you echo the data out? is it using var_dump?

    AAnd if it is, How can I change it to a MYSQL Update type of format?

     

     

    Thanks for your time,

    Ara

  11. Hi,

     

    Ok so this is the code:

    <?php
    $lines = file('players.txt');
    
    $myLine = getLine(1);
    echo $myLine[0]." ".$myLine[1]."etc".$myLine[10]."<br>";
    function getLine($line)
    {
       global $lines;
       return explode(" ", trim(str_replace("  "," ",$lines[$line])));
    }
    
    
    //other extended option
    $player = getPlayer();
    echo $player['Name'];
    echo $player['num1'][0];
    echo $player['num1'][1];
    echo $player['num1'][2];
    
    $tmpLine = 0;
    $player = 1;
    while($details = getPlayer($player)) //loop until false
    {
        var_dump($details); //dump data // change to echo data correctly
        $player++; //edit: oops need this line!
    }
    
    function getPlayer($player)
    {
       $player--;
       $player = $player * 20
       //Check first line
       if(empty($lines[$player+1])){
       return false;
       }
       //Setup details
       $details = array();
       $details['num1'] = getLine($player+1);
    //Add other line extractions (2-13)
       $details['Name'] = $lines[$player+14]; //Milan Hnilicka
       $details['Blank'] = $lines[$player+15]; //?
       $details['drafted'] = $lines[$player+16]; //drafted
       return $details;
    }
    
    ?>
    

     

    And i get this error:

    Parse error: syntax error, unexpected T_IF in /home/liguehs/public_html/converter/texttosql.php on line 33

     

    And line 33 is:

    if(empty($lines[$player+1]))return false;
    

     

    I tried:

       if(empty($lines[$player+1])){
       return false;}
       

     

      But same error.

     

     

      Once again thanks for all your help,

      Ara

     

  12. Hi

    OK now I go back to feeling dumb lol.

     

    I am at decoding line 6, and so far(without the $x):

    echo getItem(1,1);
    echo getItem(1,2);
    echo getItem(1,3);
    echo getItem(1,4);
    echo getItem(1,5);
    echo getItem(1,6);
    echo getItem(1,7);
    echo getItem(1,;
    echo getItem(1,9);
    echo getItem(1,10);
    echo getItem(2,1);
    echo getItem(2,2);
    echo getItem(2,3);
    echo getItem(2,4);
    echo getItem(2,5);
    echo getItem(2,6);
    echo getItem(2,7);
    echo getItem(2,;
    echo getItem(2,9);
    echo getItem(2,10);
    echo getItem(3,1);
    echo getItem(3,2);
    echo getItem(3,3);
    echo getItem(3,4);
    echo getItem(3,5);
    echo getItem(3,6);
    echo getItem(3,7);
    echo getItem(3,;
    echo getItem(3,9);
    echo getItem(4,1);
    echo getItem(4,2);
    echo getItem(4,3);
    echo getItem(4,4);
    echo getItem(4,5);
    echo getItem(4,6);
    echo getItem(5,1);
    echo getItem(5,2);
    echo getItem(5,3);
    echo getItem(5,4);
    echo getItem(5,5);
    echo getItem(5,6);
    echo getItem(6,1);
    echo getItem(6,2);
    echo getItem(6,3);
    echo getItem(6,4);
    echo getItem(6,5);
    echo getItem(6,6);
    

     

    And I still have 14 lines to go, was wondering if something like this would make more sense:

    Idea:

    Have a variable(x), that incremets by one on each line.

    so that it would go 1 for the 1st one, 2 for the 2nd etc.

    And when it reaches 20. It keeps going but, but it restarts from the first getItem.

     

    And then you have a 2nd variable (i), that is equal to x, and the i variable, helps us with while loop,

    everytime it reaches 20, it restarts....

     

    What do you think?

  13. Thanks,

     

    I feel a bit smart now xD lol

     

    But how can I put it in a loop?

     

    I tought maybe:

    $i = Add a number everytime there is a new line;
    while ($i <= 20)
    {
    run code
    }
    

     

    Coud that work?

    And if it coud, how can I add a number everytime there is a line?

  14. Yeah but if its for one player, it isnt that much of a deal.

     

    But there is 3500 players...

    So I would have to give likes 10 000 000:

    echo getItem(3,3);
    

     

    Is there a way of putting it in a loop.

     

    I was thinking something like, ( in a while loop):

    $x= (lets say line) 1;
    echo getItem(3,$x);
    $x = $x = 20;
    
    

     

    Would that make sens?

     

     

    Thanks for your time and help,

    Ara

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