Forum Moderators: coopster
The Question:
How can I pass along and access all rows from my query and then insert them into my local mysql database. I read that maybe a multi-dimensional array that contained all rows from my query could maybe do it but i'm a little lost. Any suggestions?
Here's my code to add to the database:
for ($i=0; array_key_exists($i, $line); $i++) {
$result = MYSQL_QUERY("INSERT INTO customerMaster SET
order_Num= '$line[$i]['order_Num']',
date= '$line[$i]['date']',
territory= '$line[$i]['territory']',
salesRep= '$line[$i]['salesRep']',
repEmail= '$line[$i]['repEmail']',
facility= '$line[$i]['facility']',
address= '$line[$i]['address']',
contact1= '$line[$i]['contact1']',
otherDiscounting='$line[$i]['otherDiscounting']'");
}
Any ideas? Line is an associative array and i did see that it does in fact pass along all the right entries.
There are some mistakes in your code - you cannot write $a = "$b['1']['bla']some text here". Moreover there's no structure INSERT.... SET. There's only INSERT INTO ... VALUES or UPDATE... SET. I'll write as if you wanted to insert new:
This should work:
for ($i=0; array_key_exists($i, $line); $i++) {$result = mysql_query("INSERT INTO customerMaster(order_Num, date, territory, salesRep, repEmail, facility, address, contact1, otherDiscounting) VALUES ('".$line[$i]['order_Num]."', '".$line[$i]['date']."', '".$line[$i]['territory']".', '".$line[$i]['salesRep']."', '".$line[$i]['repEmail']."', '".$line[$i]['facility']."', '".$line[$i]['address']."', '".$line[$i]['contact1']."', '".$line[$i]['otherDiscounting']."'");
}
Best regards
Michal Cibor