This is the POST array I am getting. I have a requirement that for 15 dishes each dish will have its own lunch & lunch quantity and dinner & dinner quantity.
i .e.
Dish1 lunch quantity dinner quantity
I want to Dish1 and its needed inputs under one array so that i can store it seprerately for specific dish.
But the problem is I can't name 'lunch', 'lunch_qty', 'dinner', dinner_qty with same name.
This is the post array am getting. I have named 'lunch' and 'dinner' checkbox as 'type' .
Array (
[dish] => Array (
[0] => BENGAN BHARTA
)
[type] => Array (
[0] => lunch
[1] => dinner
)
[lunch_qty] => Array (
[0] => 12
)
[dinner_qty] => Array (
[0] => 2
)
)
Required result
Array (
[dish] => Array (
[0] => BENGAN BHARTA
[dish0_type] => Array (
[0] => lunch
[1] => dinner
)
[dish0lunch_qty] => Array (
[0] => 12
)
[dish0dinner_qty] => Array (
[0] => 2
)
)
Please understand i want to associate each dish and its lunch, dinner, lunch_qty, dinner_qty
This is my code, i have written to insert it into database,But i am ended into inserting redundant values
$post_data=$this->input->post();
$count=count(array_filter($_POST));
for($i=0;$i<$count;$i++) {
$dish=$post_data['dish'][$i];
$dessert=$post_data['dessert'];
$type=$post_data['type'][$i];
$pulav=$post_data['pulav'];
$rice=$post_data['rice'];
$chapati=$post_data['chapati'];
$lunch_qty=$post_data['lunch_qty'][$i];
$dinner_qty=$post_data['dinner_qty'][$i];
$qry="INSERT INTO alacarte
(dish,rice,pulav,chapati,dessert,type,lunch_qty,dinner_qty)
VALUES ('".$dish."','".$rice."','".$pulav.
"','".$chapati."','".$dessert."','".$type.
"','".$lunch_qty."','".$dinner_qty."') ";
$query=$this->db->query($qry);
}