Jump to content

Adding Values from looped input fields


adamking008

Recommended Posts

Hi i am a bit of a codeigniter newbie, I need a set of values inserting to a databse table, the inputs are created via a foreach loop.

 

<? foreach ($items as $item){echo'
      <div class="items-row">
      
        <label for="name_'.$item['item_id'].'">'.$item['item_name'].'</label>
        <div class="item_input"><input type="text" name="quantity[]" id="'.$item['item_name'].'" value="0"></div>
        <input type="hidden" name="item_id"  value="'.$item['item_id'].'">
        <input type="hidden" name="user_id"  value="'.$moving_basics_id.'">
      </div>'; }
?>

 

Each item is displayed with a Quanity toggle, and a user id and item id.

 

How would i go about inserting each value into a database table?

 

Thanks

 

Adam

 

 

Link to comment
https://forums.phpfreaks.com/topic/286876-adding-values-from-looped-input-fields/
Share on other sites

give name as array for each field, as

<?php
      foreach ($items as $item)
      {
         echo'<div class="items-row">
              <label for="name_'.$item['item_id'].'">'.$item['item_name'].'</label>
               <div class="item_input"><input type="text" name="quantity[]" id="'.$item['item_name'].'" value="0"></div>
               <input type="hidden" name="item_ids[]"  value="'.$item['item_id'].'">
               <input type="hidden" name="user_ids[]"  value="'.$moving_basics_id.'">
               </div>'; 
      }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.