stfc_boy
09-11-2009, 07:22 PM
Hello All,
I’ve put together a script which takes a tab delimited file with surnames in it and grabs those names and puts them in a database table:
Now here’s a snippet of what the tab delimited file looks like
http://www.inspireaway.co.uk/td.jpg
Now as you will see the tab delimited file grabs the values across and then moves onto the next line and works across again etc, and it works nicely.
Now my problem in my script is one thing where I create an $i value and add one to it
$i = '13454'
foreach ( $data as $line ) {
$val = trim ($line);
$arr = explode ("\t", $val);
$season = '20042005'; //Define the season
$i = '13454' //Increment by one after every LINE - This is the problem!
foreach($arr as $val) {
$val_new = str_replace("#", "", $val); //Replace # in excel
$query = "INSERT INTO parser_player_names (player_name,report_id,season) VALUES ('".$val_new."','".$i."','".$season."')";
mysql_query($query)
or die(mysql_error());
$i++;
}
}
Basically here i’ve set my value to 1354 and I want it to increment by one (i++ which it does) by ONLY increment by one AFTER EACH LINE, and NOT after each individual record has been parsed into my database which it currently does.
Can anyone help
Thanks
I’ve put together a script which takes a tab delimited file with surnames in it and grabs those names and puts them in a database table:
Now here’s a snippet of what the tab delimited file looks like
http://www.inspireaway.co.uk/td.jpg
Now as you will see the tab delimited file grabs the values across and then moves onto the next line and works across again etc, and it works nicely.
Now my problem in my script is one thing where I create an $i value and add one to it
$i = '13454'
foreach ( $data as $line ) {
$val = trim ($line);
$arr = explode ("\t", $val);
$season = '20042005'; //Define the season
$i = '13454' //Increment by one after every LINE - This is the problem!
foreach($arr as $val) {
$val_new = str_replace("#", "", $val); //Replace # in excel
$query = "INSERT INTO parser_player_names (player_name,report_id,season) VALUES ('".$val_new."','".$i."','".$season."')";
mysql_query($query)
or die(mysql_error());
$i++;
}
}
Basically here i’ve set my value to 1354 and I want it to increment by one (i++ which it does) by ONLY increment by one AFTER EACH LINE, and NOT after each individual record has been parsed into my database which it currently does.
Can anyone help
Thanks