General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 20th, 2004, 04:19 PM
sevans sevans is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 2 sevans User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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:brandsELETE[]
2]school name: teacher name:room:building:brandsELETE[]
3]school name: teacher name:room:building:brandsELETE[]
4]school name: teacher name:room:building:brandsELETE[]

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

Reply With Quote
  #2  
Old January 20th, 2004, 06:00 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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']

Reply With Quote
  #3  
Old January 20th, 2004, 08:22 PM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
may i see the code plz

Reply With Quote
  #4  
Old January 20th, 2004, 08:36 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
My code?

to handle the multiple checkboxes, I used this:

PHP Code:
foreach ($_GET['field'] AS $value) {
    
$sql "INSERT INTO table (field) VALUES ('$extra')";
    
mysql_query ($sql);


Reply With Quote
  #5  
Old January 20th, 2004, 09:31 PM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
not yours =[...his

Reply With Quote
  #6  
Old January 20th, 2004, 10:13 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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...

Reply With Quote
  #7  
Old January 21st, 2004, 10:50 AM
sevans sevans is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 2 sevans User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > checkboxes


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT