Hey all,
I am trying to insert some data into a mysql database, but the info has to be looped via php in a manner that I am having a hard time figuring out. I have a 5x5 table (just like one in excel) I do a single insert for top headers, that works fine.. then I want to do an insert per row on the table.. the insert would contain one side header and a few data fields that match the top header's variable. So simply:
______top1---top2---top3
Side1 --- D1 --- D2 --- D3
Side2 --- D4 --- D5 --- D6
$header_top and $header_side are both based off of a variable lets say 5.(to make 5x5 table) The insert below is just part of it as I have taken out the basic stuff and just have the loops. I want a single database insert for each row of the table.. ie.. one for Side1, one for Side2.. but the data D1, D2, etc should match with the side1 or side2. The loops I have below are doing the correct number of inserts, but the data is simply repeating data from the first row each time. Data is being returned in an array so it is simply being counted as data1 thru whatever depending on how many fields in the table like above(seen as $data[$k] below). I need the info to insert into the same columns for each one though.. ie D1 and D4 need to both insert into the same column in the database. Anyone have any ideas?
So in short The data variable needs to count up to the $header_top variable.. if Ht is 5, then data needs to go , data1,data2,data3,data4,data5.. then stop, and remember it stopped at data5.. then on the second insert, it needs to start at data6 then run up thru data7,data8,data9, and data10.. etc.. for each insert.. just needs to remember where it ended on the previous insert and pick up from there on the next. any way to do this?
for($a = 0; $a < count($header_side); $a++)
{
$tmpquery1 = INSERT INTO .....(field1,field2,field3...
for($c = 0; $c < count($header_top); $c++)
{
$datab = "data$c";
$tmpquery1 .= ",$datab";
}
....) VALUES ( '$field1','$field2','$field3',......
for($k = 0; $k < count($header_top); $k++)
{
$data1 = $data[$k];
$tmpquery1 .= ",'$data1'";
}
....);
}