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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:39:30+00:00 2026-05-18T05:39:30+00:00

I have inserted some check box values in mysql database using PHP And in

  • 0

I have inserted some check box values in mysql database using PHP

And in the below image i have fetch the values:

alt text

Now i need the o/p like the below image: The values which i inserted in the database should be checked

alt text

Hope now its clear.

Thanks in advance..

  • 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-18T05:39:30+00:00Added an answer on May 18, 2026 at 5:39 am

    You should have a table of available options (in this case, something like a cities table), and then a user-to-cities look-up table. Then you can loop over the cities, but also fetch which cities the user has checked.

    A sample, without knowing your database structure, would be as follows:

    $uid = $_SESSION['user']['id']; // your logged in user's ID
    
    $cities = array();
    
    // get an array of cities
    $sql = "SELECT id, name FROM cities";
    $res = mysql_query($sql);
    while ($row = mysql_fetch_object($res)) {
        $cities[$row->id] = $row->name;
    }
    
    // get an array of cities user has checked
    $sql = "SELECT DISTINCT city_id FROM users_cities WHERE user_id = '$uid'";
    $res = mysql_query($sql);
    while ($row = mysql_fetch_object($res)) {
        $checked[] = $row->city_id;
    }
    
    // this would be templated in a real world situation
    foreach ($cities as $id => $name) {
        $checked = "";
        // check box if user has selected this city
        if (in_array($checked, $id)) {
            $checked = 'checked="checked" ';
        }
        echo '<input type="checkbox" name="city[]" value="'.$id.'" '.$checked.'/>';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic HTML form that gets inserted into a server side div
I'm trying to make an AJAXy submission and have the resulting partial be inserted
In our desktop application, we have implemented a simple search engine using an inverted
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
(resolved: see bottom) I have the following code snippet: Protected Sub SqlDataSource1_Inserted(ByVal sender As
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
Have you determined a maximum number of characters allowed in FCKEditor ? I seem

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.