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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:03:04+00:00 2026-05-30T07:03:04+00:00

I am using a loop to create dynamic checkboxes as described here Everything works

  • 0

I am using a loop to create dynamic checkboxes as described here

Everything works as expected and I have successfully created a table with 2 columns: userid and preferences.
Each checkbox has a unique preference value associated and If it is checked, then php stores it in a mysql database.

Now i need to repopulate the checkboxes if the user comes back on the page another day.

My idea (maybe not good enough..)

SELECT preference FROM Preference table WHERE UserId=CurrentUserId

and I can call the query result ---> $result[]

Now I got all the preferences of a certain user in a variable and I can make a loop with a IF condition when creating the dynamic checkboxes:

IF $result equals the current checkbox id then write checked

but I am not fully sure how to make it work and if it would work..any ideas?

  • 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-30T07:03:06+00:00Added an answer on May 30, 2026 at 7:03 am

    It is exactly as you said.

    1. Get the preferences from database for the current online user ($clientId).

      $query = "SELECT preference FROM Preference WHERE userId = $clientId";
      $res = sql_query($query, $connection);
      while($userPreference = mysql_fetch_array($res))
        $userPreferences[$userPreference] = true;
      

      I will assume they have a unique identifier called preference.

    2. Iterate over all the preferences, checking against the selected $userPreferences from database.

      foreach($preferences as $preference) {
        $checked = $userPreferences[$preference] ? 'checked' : '';
        echo "<input type='checkbox' value='{$preference}' $checked />";
      }
      

    Something like this should be enough to recreate the layout and choose user preferences.

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

Sidebar

Related Questions

first time posting here. I'm using a loop to create 3 buttons, but my
How to create dynamic incrementing variable using for loop in php? like wise: $track_1,$track_2,$track_3,$track_4.....
I'm trying to create dynamic balls by using a for loop. For some reason
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
In My last post I asked : How to create dynamic incrementing variable using
Trying to build dynamic output from json and using jq/template tmpl display rows/columns. Somehow
I am trying to create a treeview dynamically using c# and asp.net. I have
Hey I have dynamic image begin created with imagecreate(), and I have random values
I'm using the jQuery audio player 'jPlayer', I have a loop which creates a
I'm using Perl, and I want to create variables in loop. So each loop

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.