If the table persists out of 2 columns only, id1
and id2
You could do the following:
$insertVals = ''; //Values go here,
$insertCols = ''; //Column names go here, alternating from id1 to id2
$counter = 0; //Will be used to iterate odd and even.
foreach ($a as $value) {
$insertVals .= "'".$value."',"; //Comma at the end is needed.
if ($counter % 2 == 0) //if even basicly
$insertCols .= 'id1,'; //DB fields do not require quotes, backticks are optional
else
$insertCols .= 'id2,';
$counter++ //Increment counter to cause odd values to occur.
}
//Remove last comma's from both strings.
$insertVals = substr($insertVals, 0, -1); //-1 removes the last char in substr.
$insertCols = substr($insertCols, 0, -1);
$query = "INSERT INTO yourtable ({$insertCols}) VALUES ({$insertVals})";
this should do the trick. Let me know if there are any errors you get since this is written straight out of the head and untested.
Regards, Sidney Liebrand