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

  • SEARCH
  • Home
  • 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 7974065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:16:04+00:00 2026-06-04T08:16:04+00:00

This code picks up the ID of the check box checked correctly, however it

  • 0

This code picks up the ID of the check box checked correctly, however it chooses the select dropdown from my first select not the one I changed. Is there a way to fix this? Im using

<select name="status[]"><option value="1">active</option><option value="0">inactive</option></select>

here is my process code.

if (isset($_POST['submit'])) {


// find out how many records there are to update

$size = count($_POST['id']);

// start a loop in order to update each record
$i = 0;
while ($i < $size) {
// define each variable
$id = $_POST['id'][$i];
$status= $_POST['status'][$i];

// do the update and print out some info just to provide some visual feedback
$query = "UPDATE users SET status = '$status' WHERE id = '$id' LIMIT 1";
mysql_query($query) or die ("Error in query: $query");
print "$status | $id<br /><br /><em>Updated!</em><br /><br />";
++$i;
}
mysql_close();
}
  • 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-06-04T08:16:06+00:00Added an answer on June 4, 2026 at 8:16 am

    I agree with the comments, however, I’ll just provide a quick answer to the question.

    I’d do something like this for simplicity in the HTML. The array indices can simply echo from a counter in PHP or entered statically if it won’t change based on anything else. Simply increase this index with each item.

    <input type="checkbox" name="id[0]" value="1"> Some Text
    <select name="status[0]">
        <option value="1">Option 1</option>
        <option value="2">Option 2</option>
    </select>
    

    Now for the PHP

    if (isset($_POST['submit'])) {
    
        foreach($_POST['id'] as $i=>$value) {
            if($value == 1) {
                // define each variable
                $id = $_POST['id'][$i];
                $status= $_POST['status'][$i];
    
                // do the update and print out some info just to provide some visual feedback
                $query = "UPDATE users SET status = '$status' WHERE id = '$id' LIMIT 1";
                mysql_query($query) or die ("Error in query: $query");
                print "$status | $id<br /><br /><em>Updated!</em><br /><br />";
            }
    
        }
        mysql_close();
    }
    

    EDIT:

    I forgot to mention you can set the value of the checkbox to whatever you need it to be. Just be sure the if($value==1) checks for a valid result (for example >0 if all of your Id’s are positive).

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

Sidebar

Related Questions

This code snippet is from C# in Depth static bool AreReferencesEqual<T>(T first, T second)
This code attempts to dynamically switch the class of the StateContainer div from StateOne
This code basically translates characters based on position in one string to the character
I realize this is not terribly different from a lot of other questions that
Okay this is a revised question from earlier today, I have included code to
Can any one help me with this code: ASP: <script type=text/javascript> function confirm_delete(div.ID)// problem
I've snatched this piece of tile collision code from another game, but in the
I am trying to check the radio box onClick using jQuery, my code is
This code randomizes 52 cards and puts 13 each in 4 box of text
how to see items that i pick on ListView ? i have this code:

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.