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 8402363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:02:16+00:00 2026-06-09T22:02:16+00:00

My question extends on the answer on this post and I couldn’t find what

  • 0

My question extends on the answer on this post and I couldn’t find what I’m looking for posted otherwise.

How do I auto select (checked) options in a checkbox list when the options are being pulled from a mySQL table (dynamic)?

Here’s what I have so far:

Pulling the committees (comms) from the table:

while ($row = mysql_fetch_assoc($comm)){
    foreach ($row as $v){
        $comms[] = $v;
        }
}

outputting pretty HTML with tidy PHP (the part I need help with):

    foreach ($comms as $comm){
       ?????????
    }

How can I output something like?:

<input type="checkbox" name="committee" value="blue" checked="checked" />blue<br />
<input type="checkbox" name="committee" value="green"  />green<br />
<input type="checkbox" name="committee" value="orange"  />orange<br />
<input type="checkbox" name="committee" value="purple" checked="checked" />purple<br />
  • 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-09T22:02:17+00:00Added an answer on June 9, 2026 at 10:02 pm

    Assuming your colors are stored in an array and your data comes back as an array (likely not the case if you’re using mysql_* functions), you can print out each checkbox, then compare its value to see if it’s in the list of “checked” colors:

    <?php
    $colors = array('blue', 'green', 'orange', 'purple');
    
    $data = array('blue', 'purple');//array pulled from database.
    
    foreach($colors as $color): ?>
        <input type="checkbox" name="committee" value="<?= $color ?>" <?= in_array($color, $data) ? 'checked="checked" ' : '' ?>/><br />
    <?php endforeach; ?>
    

    By the way, you should stop using mysql_* functions. They’re being deprecated. Instead use PDO (supported as of PHP 5.1) or mysqli (supported as of PHP 4.1). If you’re not sure which one to use, read this article.

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

Sidebar

Related Questions

I couldn't find the answer to this in any other question. Suppose that I
Please just answer the question otherwise do not respond to this question. Let me
I feel a bit stupid as i can't find the answer to this question,
I have run into a wall trying to find an answer to this question
This is a question that extends from the originally posted here: Link to loading-xaml
This should be a fairly simple question to answer. I looked around and couldn't
I know, I know... Eric Lippert's answer to this kind of question is usually
I originally posted this question on the miglayout forum and after 534 views and
I have touched on this question here , where Christopher gave an answer to
edited for clarity I feel like this question already has an answer, but I

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.