|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
checkboxes
I have checked numerous threads, and can not find my ansywer.
I have a mysql database full of computer assets broken down by my schools. When the techs display that school, for example: 1]school name: teacher name:room:building:brand s ELETE[]2]school name: teacher name:room:building:brand s ELETE[]3]school name: teacher name:room:building:brand s ELETE[]4]school name: teacher name:room:building:brand s ELETE[]If they check on checkbox 1 and 3, that is what I want to delete from MYSQL. It delete the first two, not 1 and 3. I have tried using isset, is_array. It still will not work correctly. I am posting this array to another PHP program, that either updates, adds, or deletes records. I can delete 1 and 3 fine, if I set up a text box and check for the value 'Y'. I don't want a textbox, I want a check box, to make it easier. checkboxes are very confusing. Any help or suggestions would be appreciated. Thank You Susan |
|
#2
|
||||
|
||||
|
I've dealt with Checkboxes in PHP before... The way I organized it was but setting the value for the check field to the respective index in the table...
For example: <input type="checkbox" name="field[]" value="1"> Item 1 <input type="checkbox" name="field[]" value="2"> Item 2 Then to handle it in php, i used a foreach on $_GET['field'] |
|
#3
|
|||
|
|||
|
may i see the code plz
|
|
#4
|
||||
|
||||
|
My code?
to handle the multiple checkboxes, I used this: PHP Code:
|
|
#5
|
|||
|
|||
|
not yours =[...his
![]() |
|
#6
|
||||
|
||||
|
lol... oh...
oh well... i see this topic come up a LOT in the forums... might as well have my code out there for others to enjoy =) perhaps sevans can use it... |
|
#7
|
|||
|
|||
|
Thank you for your help. I took your sugguestion, then added some. I came across this tibit of infomation:
HTML Forms only send the value of a checkbox when the checkbox is checked, otherwise it's like not having the checkbox on the form at all. Keep this in mind when you're updating a record and the checkbox is not checked. It then dawned on my what you where referring to: For example: <input type="checkbox" name="field[]" value="1"> Item 1 <input type="checkbox" name="field[]" value="2"> Item 2 So, what I did was : <input type="checkbox" name="field[]" value='$count' because each query search will result in a different number of rows being displayed, I set $count=1; then $count+=1; until completed displaying. When I post the data, I then check to see what values where passed, and then I know which row I am deleting. Thanks again for your help. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > checkboxes |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|