For each loop not executing more than once in php -


i have 2 fields in form 1 name , other email this.

<td class="left"><input style="  width: 30%; text-align: center;" type="text" name="name[]" value="<?php echo $geo_zone['name']; ?>" /></td> <td class="left"><input style="  width: 30%; text-align: center;" type="email" name="email[]" value="<?php echo $geo_zone['email']; ?>" /></td> 

there name array types can store multiple values in them on run time because form generated on run time , may have multiple names , emails depending on database result.

in controller iam fetching these values in print_r() iam getting writes results. when execute each loop runs 1 time , inserts last row in database.

$name= $this->request->post['name'];  $email= $this->request->post['email'];  foreach( $name $key => $n ) {  $this->data['geo_zone_id']=$this->model_module_shipping_pools->get_geo_zone_id($n);  $geo_zone_id=$this->data['geo_zone_id']; $geo_zone_id=$geo_zone_id[0]['geo_zone_id'];  $this->model_module_shipping_pools->drop_data(); $mail=$email[$key]; $this->model_module_shipping_pools->insertdata($geo_zone_id,$mail); 

i have no idea why running 1 time. working in opencart.

you need multiple input tag same array name have array value!

for example (i don't know how generate original html) may have:

<td class="left"><input style="  width: 30%; text-align: center;" type="text" name="name[]" value="<?php echo $geo_zone['name'][0]; ?>" /></td> <td class="left"><input style="  width: 30%; text-align: center;" type="text" name="name[]" value="<?php echo $geo_zone['name'][1]; ?>" /></td> ... 

see example on how use array here


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -