PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have been struggling with this problem for some time now and decided that it might be time to ask if anyone has run into this problem before, or has ideas on how to fix it.
I have a list containing check boxes. The list is generated from an array built from a mysql database. When a check box is checked and form submitted, the value is saved to a second table.
When the user returns to this page I want to have the previous items they have already checked show up as being checked.
<?php do { ?>
<input name="selectedfile[]" type="checkbox" value="<?php echo $row_filelist['ID']; ?>" <?php if ( $row_FiletoPagelist['file'] == $row_filelist['ID']) { echo "checked='checked'"; } ?>>
<?php } while ($row_filelist = mysql_fetch_assoc($filelist));?>
currently this works, but only shows one check box as being checked. If I have ten items in the list and five get checked, the last checked item will show up as being checked, the previous four are blank.
They are named the same for two reasons. 1 the are saved into an array which I use to update the database, as such they need to be named with the same name and []'s, and 2 because the list is dynamically generated.
The problem isn't with the name portion of the input code, but with the if then statement. I suspect that when it takes the two variables to compair, one is looping (filelist) while the other is not (filetopagelist).
Does anybody know how to stop a loop when it finds a match?
that makes the check boxes for me. I then select however many I want and on the next page it looks for the number checked and processes that many times.
Yep that works too. Right now It works perfectly as far as listing the number of check boxes that I need from the array.
My problem is I need the check boxes to actually start as being 'checked'
Lets say you have an internet mail box that has several customizable settings, all doen with check boxes. You check the options you want and save it. Later on, few weeks or months, you want to change your options. When you load the options page those check boxes start off as being checked with whatever you previously selected.
I am trying to accomplish this. I have a list being loaded from an array, and I wish to have the saved options start as being a 'checked' checkbox.
Not sure you understand. That code will go through and check everything in the list automatically. I do not want that. I am trying to set it up so that the first time someone visits, nothing is checked. they make thier selections, save it, then, if they return to the page thier selections (which may not be every check box) are selected while the options they did not choose are not selected.
I have two tables. table one Filelist - is the list the check boxes generate from. Table two - FiletoPagelist - is the table holding the values of the check boxes that have been selected and saved.
The idea is to have the list generate and check to see if the filelist and filetopagelist contain the same value, if so the box should be checked. if not it should be left blank.
I've checked the arrays and each shows all the correct values that I need however I had to loop them seperately.
But your right, when it does the compairison, the files array loops, while the filetopage doesn't seem to loop. it only takes the last value in the array for compairison.
I dont know how to get both to loop at the same time. When I try to do a loop within a loop, it may find a match with the first item and echo the 'checked', but when it does the next cycle in its loop and doesn't find a match I think it overwrites the 'checked' from the first loop and shows nothing.