i need to join those two peice of code the first peice of code takes a csv file from a textarea formats it and put it into a mutidimentional array
<?php
if(isset($_POST['TextArea1'])){
$str = $_POST['TextArea1'];
$patterns = array("/\t+/", "/ +/"); //set up an array of items to replace
$str = preg_replace($patterns, ' ', $str);
$lines = explode("\n", $str);
$parsedArray = array();
foreach ($lines as $line) {
$parsedArray[] = str_getcsv($line, ' ', '"', '\\');
}
echo "<pre>";
print_r($parsedArray);
echo "</pre>";
}
?>
<form method="post" >
<textarea name="TextArea1" id="TextArea1" rows="10" cols="50"></textarea>
<input type="submit" value="Parse" name="submit" />
</form>
now i need to insert the data into my database for this i have this peice of code
$array = csv_array(); // this is array from csv
$id = $array[0][0];
$Name = $array[0][1];
$Position = $array[0][2];
$Reference = $array[0][3];
$cityguards = $array[0][4];
$ballistas = $array[0][5];
$rangers = $array[0][6];
$guardians = $array[0][7];
$templars = $array[0][8];
$berserkers = $array[0][9];
$mages = $array[0][10];
$scouts = $array[0][11];
$crossbowmen = $array[0][12];
$paladins = $array[0][13];
$knights = $array[0][14];
$warlocks = $array[0][15];
$rams = $array[0][16];
$catapults = $array[0][17];
$frigates = $array[0][18];
$sloops = $array[0][19];
$wargalleons = $array[0][20];
$barons = $array[0][21];
$total = $array[0][22];
$total1 = $array[0][23];
$host = 'localhost';
$user = 'xxxxxx';
$pass = 'xxxxxxxx';
$db = 'xxxxxx';
for($i = 1; $i < count($array); $i++){
//this is where sql goes
// connect to database
$link = mysql_connect ($host,$user,$pass) or die ('Erreur : '.mysql_error() ) ;
mysql_select_db($db) or die ('Erreur :'.mysql_error()) ;
$sql = "INSERT INTO military($id, $Name, $Position, $Reference, $cityguards, $ballistas, $rangers, $guardians, $templars, $berserkers, $mages, $scouts, $crossbowmen, $paladins, $knights, $warlocks, $rams, $catapults, $frigates, $sloops, $wargalleons, $barons, $total, $total1 )
VALUES($array[$i][0], $array[$i][1], $array[$i][2], $array[$i][3], $array[$i][4], $array[$i][5], $array[$i][6], $array[$i][7], $array[$i][8], $array[$i][9], $array[$i][10], $array[$i][11], $array[$i][12], $array[$i][13], $array[$i][14], $array[$i][15], $array[$i][16], $array[$i][17], $array[$i][18], $array[$i][19], $array[$i][20], $array[$i][21], $array[$i][22], $array[$i][23],)";
$db->mysql_query($sql,$link);
my question is can i do this $array = $parsedArray();
and put the second part of the code inside the loop of the first code replacing the print_r ?
ty
jethaya