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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:22:40+00:00 2026-05-24T20:22:40+00:00

I have a form that has multiple categories. They are separated by checkboxes, so

  • 0

I have a form that has multiple categories. They are separated by checkboxes, so one could check any number of categories that their post/story will be in.

The values are stored inside a db row separating them by commas while INSERT

GetSQLValueString(implode($_POST['r_category'],", "), "text"),

So in the database I could have an entry that looks like this:

2,3,6,12

Which those are category numbers.

I am now building an edit form feature to use to Edit and UPDATE these records. I can not find a way to “EXPLODE” the values into checkboxes on the edit form??

So if you log in and go to the ENTRY that you want to edit for example, I have Checkboxes separating the Categories, so it will be easy to check and uncheck to add and not add… I have tried everything I could to get the values to POST and be checked when viewing this Edit Form.

Here is an example of one of my Category Check boxes on my edit form page, but it is not working when I have multiple Categories, like the example above.. 2,3,6,12 ?? :

  <input type="checkbox" name="r_category[]" 
<?php if (!(strcmp("2", $row_Recordset2['r_category']))) {
              echo "checked=\"checked\"";} ?> value="2" />Cat 2

Thanks in advance NINJAS!!

  • 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-24T20:22:41+00:00Added an answer on May 24, 2026 at 8:22 pm

    I can not find a way to “EXPLODE” the values into checkboxes on the edit form

    This line is so close to the answer that I’m seriously wondering if this is a joke post.

    Given your database structure as it is, you can use the explode() function to break the value into an array based on a delimiter. For example:

    $values = "1,2,3,4";
    $array_of_values = explode(",", $values);
    

    After this, $array_of_values will contain an array of four elements with the values of 1, 2, 3, and 4 respectively.

    When deciding whether or not to display the checkbox as checked, you can use the in_array() function to make that call:

    if (in_array("2", $array_of_values)) {
      echo 'checked="checked"';
    }
    

    Beyond that, let me take this opportunity to second what @MarkB said in the comments on this question: it’s a bad idea to hold multiple values in a single database field. It makes searching for things harder, it makes adding values harder… it just makes everything more complex than it needs to be.

    The best way to handle this would be to have a many-to-many table which stores rows of items and categories, with one row for each category that an item belongs to.

    In other words, where you currently have this:

    Item | Category
    ---------------
    123  | 1,2,3,4
    

    You would instead have a table that looks like this:

    Item | Category
    ---------------
    123  | 1
    123  | 2
    123  | 3
    123  | 4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that has multiple fields, and for testing purposes is there
I have a web form that has multiple ListBoxes, TextBoxes, DropDowns. If I put
i have a form that has a multiple select drop down. a user can
I have a form that has 8 columns and a variable number of rows
I have a form that has a series of check boxes and some line
I have a form that has two buttons on it, one yes, one no,
If I have a form element that has multiple validators attached to it (3
I have a window form application, and it has multiple threads running that would
I have a form that has multiple select drop downs. i.e. Item 1: <select
i have a form that has select element <select name=adddisplaypage[] id=adddisplaypage multiple=multiple> <option value=all

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.