Array (
[modo_prep] =>
[modo_serv] =>
[id_prod_comp] => 18
[id_ingrediente] =>
Array (
[0] => 16
[1] => 17
[2] => 18
)
[qtd] => Array (
[0] => 10
[1] => 100
[2] => 1000
)
[rend_kg] => Array (
[0] => 20
[1] => 200
[2] => 2000
)
[submit] => Guardar
[id_receita] => 0
)
(post array) and need to be dynamic insert, so i want to do a universal post function to insert. with simple array its ok 2 dimensoions there is a problem because i cannot match 1st value of N and so on, i need to be each array but same position each one sub-arrays to put in insert sentence.
so example: i have 1 row product, dinamic jquery (id_product[]) and i dont want to put the keys i want the script read all post data and put simple array in one table and the other N in other mysql table and each loop create 1 record with same key of each N sub arrays. row 1 has 3 fields it comes with 3 arrays, each row but if i put N i need to deal with that.
Code:
<?
ERROR_REPORTING(E_ERROR);
if($_POST['submit'] == TRUE){
$table = 'receitas';
$table2 = 'receitas_componentes';
$element1 = array();
$element3 = array();
$i=0;
foreach ($_POST as $key =>$valor){
if( $key != 'submit'){
if( !is_array($valor )){
$element1[$key] = $valor;
$colnames = "`".implode("`, `", array_keys($element1))."`";
$colvals = "'".implode("', '", $element1)."'";
$query_element1="INSERT INTO `".$table."` (".$colnames.") VALUES (".$colvals.")";
}else{
//echo $colvals = "'".implode("', '", $element1)."'";
$count = sizeof($valor);
extract_1_array($valor,0);
//else
}
//not submit
}
}
//echo $query_element1;
//mysql_query($query_element1);
$id_receita= mysql_insert_id();
//$_POST['id_receita']=$id_receita;
}
function extract_1_array($valor, $increment){
$i=0;
foreach ($valor as $key2 => $ingredientes){
$subarray[$i] .=$ingredientes ;
$i++;
}
echo $subarray[$i]; echo("<br>");
//$var10= implode($subarray[0]);
}
//echo $var10;
?>
<br><br><br><br><br><br><br><br>
blank