I have a PHP script that looks like this:\[code\]foreach($_POST as $key => $value) { $value = http://stackoverflow.com/questions/15669561/$this->input->post($key); $ingredientQTY = $this->input->post('ingredientQTY'); $measurements = $this->input->post('measurements'); $ingredientNAME = $this->input->post('ingredientNAME'); $ingredientsROW[] = array($ingredientQTY, $measurements, $ingredientNAME); for ($i = 0, $count = count($ingredientQTY); $i < $count; $i++) { $rows[] = array( 'ingredientamount' => $ingredientQTY[$i], 'ingredientType' => $measurements[$i], 'ingredientname' => $ingredientNAME[$i], 'recipe_id' => $recipe_id, 'order' => $i + 1, 'user_id' => $user_id ); $sql = "INSERT `ingredients` (`ingredientamount`,`ingredientType`,`ingredientname`, `recipe_id`, `order`, `user_id`) VALUES "; $coma = ''; foreach ($rows as $oneRow) { $sql .= $coma."('".implode("','",$oneRow)."')"; $coma = ', '; } $this->db->query($sql); } break; }\[/code\]which inserts into a database called ingredients. My form looks like this:
Here's my HTML: \[code\]<span> <input type="text" class='pluralizer small' name="ingredientQTY[]" placeholder='QTY'/> <select name='measurements[]'> <option value='' name='' checked='checked' data-single="--" data-other="--">--</option> <?foreach ($measurements as $m):?> <option value='http://stackoverflow.com/questions/15669561/<?=$m->measurement;?>' data-single="<?=$m->measurement;?>" data-other="<?=$m->measurementPlural;?>"> </option> <?endforeach;?> </select> <input type="text" name="ingredientNAME[]" class="ingredient" placeholder='Ingredient'/> <a class='float-right delete-button deleteThis' style='margin:10px 2px;' href='http://stackoverflow.com/questions/15669561/#'><img src='http://stackoverflow.com/questions/15669561/<? echo base_url()."public/img/delete.png";?>' height='11' width='11' /></a></span>\[/code\]For some reason, when I insert (which works fine, other than the issue I'm going to mention) the first row I insert gets duplicated in the mysql table \[code\]ingredients\[/code\], but all the subsequent rows are just inserted once. Why the heck does it do that?Thanks for all help! If you need any more details, just ask!