Jump to content

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>'; 
      }
?>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.