Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6156147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:33:35+00:00 2026-05-23T20:33:35+00:00

I am setting up a form using this PHP that loops through all records

  • 0

I am setting up a form using this PHP that loops through all records a user may have:

    <?php foreach ($items as $row): ?>
            <tr>
                <td>
                    <?php echo form_hidden('id', $row->id); ?>
                </td>
                <td>
                    <?php echo '<strong>' . $row->name . '</strong>'; ?>
                </td>
                <td>
                    <?php echo form_input('number', $number); ?>
                </td>
                <td>
                    <?php echo form_input('registry', $registry); ?>
                </td>
                <td>
                    <?php echo form_checkbox('OK', $ok, $ok); ?>
                </td>
            </tr>
    <?php endforeach; ?>

This gives me a form with the following look:

enter image description here

The idea here is that each row belongs to a unique ID/row in the database, and I would like to allow the user to edit all on the same page/form, using a single submit button.

What would be the best way of implementing this?

When this data is submitted, there should be a way of looping through each packet of information (from each user) in my controller. Would this be done via ajax/json?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:33:35+00:00Added an answer on May 23, 2026 at 8:33 pm

    This does not use codeigntier, but you should be familiar with the general technique before attempting to use CI to shortcut this process. Codeigniter will help you with rendering the form elements, performing validation, escaping your input and performing your query – but it will only help you (do anything) if you understand the basic principles involved. Hope this helps

    MARKUP

    <form action="/process.php">
    <div>
        <h2>GORDON</h2>
        <input type="text" name="user[1][number]" /> <!-- The number corresponds to the row id -->
        <input type="text" name="user[1][registry]" />
        <input type="checkbox" name="user[1][ok]" value="1" />
    </div>
    <div>
        <h2>ANDY</h2>
        <input type="text" name="user[242][number]" />
        <input type="text" name="user[242][registry]" />
        <input type="checkbox" name="user[242][ok]" value="1" />
    </div>
    <div>
        <h2>STEWART</h2>
        <input type="text" name="user[11][number]" />
        <input type="text" name="user[11][registry]" />
        <input type="checkbox" name="user[11][ok]" value="1" />
    </div>
    
    <input type="submit" />
    

    PHP

    $users = $_REQUEST['user'];
    
    foreach ($users as $rowId => $info){
    
        // YOU SHOULD MAKE SURE TO CLEAN YOUR INPUT - THIS IS A GUESS AT WHAT YOUR DATA TYPES MIGHT BE
        $id = (int) $rowId;
        $number = (int) $info['number'];
        $registry = mysql_real_escape_string($info['registry']);
        $ok = (int) ($info['ok']);
    
        $q = "UPDATE user SET number = $number, registry = '$registry', ok = $ok WHERE id = $id";
        mysql_query($q);
    
        // You may want to check that the above query was sucessful and log any errors etc.
    
    }
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I m setting up 5 sliders using jQuery UI in a form like this:
I have some code that works and changes the style sheet using a form.
I have a form that has a dropdown menu i need the user to
this may seem trivial but I'm setting up, on a profile form page I'm
I'm writing a simple app that's going to have a tiny form sitting in
Using ajax+php in my signup form. There are 2 validations: JS side frontend and
I have this web page I'm developing that displays multiple images of one product
I am using the same php code I have always used to try and
So I have this form on a page and trying to validate values with
I have a form for a user to change their settings. It has 5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.