I want to insert multidimensional array to mysql using insert
with the below code it inserts as below..
"insert into table (col1) value(1)";
"insert into table (col2) value(2)";
"insert into table (col3) value(3)";
"insert into table (col4) value(6)";
...
"insert into table (col1) value(7)";
"insert into table (col2) value(5)";
"insert into table (col2) value(3)";
"insert into table (col2) value(8)";
...
instead it should insert
"insert into table (col1,col2,col3,col4,col5) values(1,2,3,6,7) "
"insert into table (col1,col2,col3,col4,col5) values(7,5,3,8) "
...
$res_arr= array(
0=>array(1,2,3,6),
1=>array(7,5,3,8),
2=>array(6,5,9,8),
....
10000
);
Below is the code I use
$maketbl = "CREATE TABLE $table(";
//$maketemp .= " id int(11) , ";
for($i=0;$i<= 5;$i++)
{
$maketbl .= " COLUMN_$i varchar(128), ";
//echo "<br>";
}
$maketbl .=")";
$maketbl = substr($maketbl,0,-3);
$maketbl.=" )";
mysql_query( $maketbl ) or die ( "Sql error : " . mysql_error ( ) );
foreach ($res_arr as $k=>$subArray)
{
foreach ($subArray as $id=>$value)
{
@$avArray[$id] = $value;
if(!empty($avArray[$id]))
{
mysql_query("insert into $table(COLUMN_$id) values($avArray[$id]))";
}
}
}