Hey everyone, I have an array of checkboxes that hold a value from 1-30, and when I first update the database it stores these values in a comma seperated list like 1,8,9,22 in the MYSQL database.

Now my question is, can I when I go to the edit page to edit the entry into the database, instead of remembering what categories each belong to, have the values automatically check the boxes that it belongs to on my edit page?

I think I just made this more confusing then what it actually is, and if you need clarity, please ask me.


4 Years
Discussion Span
Last Post by patk570

My edit page is strictly PHP quering from the database using a FETCH command. for the text fields. The categories are in a checkbox array, and using the command categories[] as the name and 1-30 as the value.


What I am trying to accomplish is:

  1. Get the values from the database so when I go to edit the page I do not have to remember 200 check marks.
  2. Streamline the process for this, if there is a better way of doing this I would love to know.
  3. I am also linking tables in my search string, so it will be something like:

    SELECT libvid.categories, categories.id
    FROM categories, libvid
    WHERE libvid.id = libvid.categories

Any and all input would be great. I thought about using an AJAX script to retreive the values, but got lost, when I was doing research on this topic, I wasn't getting a hits. I know there is a way, but I have no CLUE on how to get all the values to be checked.


I just got an idea but need to run it by ya's...

<input type="checkbox" <?
$CheckboxChecked = $details['categories'];
if ($CheckboxChecked==1){
    echo 'checked="checked"';
    } else {
    echo '';
?> value="1">Hamstrings

would this work and would I have to do this with everyone?


I fixed the issue i was having, and it is working really good now.

Thanks for the help

//put query string above to get results

$cats_array = explode(",", $myEdit['categories']);

then below that in the checkbox array i have:

     <input name="categories[]" 
        if (in_array(1, $cats_array)){
        echo 'checked="checked"';
        } else {
        echo '';
    value="1" type="checkbox" />Quadriceps

Now it is working like a charm and I do not have to remember what category each belong to.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.