PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

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:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old July 11th, 2004, 02:11 PM
jgothelf jgothelf is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 jgothelf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Updating Values with Checkboxes

I am displaying multiple records each with a checkbox that has the ID (sendTo) which is equal to "id" in my table. I want to update the records that are checked with the SQL below:

$sql = "UPDATE members SET sendTo=1 WHERE id='$sendTo'";

However, after clicking Submit, only one of the records will update. Any ideas on how I can run this query for multiple checked records? Thanks!

Reply With Quote
  #2  
Old July 12th, 2004, 06:26 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
If you name the checkboxes as sendTo[] rather than just sendTo then you will get an array of values after submission. Then you can loop through the array to build an appropriate SQL query to update all of them rather than just one.

-KM-

Reply With Quote
  #3  
Old July 12th, 2004, 06:38 AM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
PHP Code:
<?php
  
if ($_SERVER["REQUEST_METHOD"]=='POST' && is_array($_POST['sendTo']) && count($_POST['sendTo'])>0) {
    
/* $key = the sendto ID, $value = on (will always be on if it is present */
    
foreach ($_POST['sendTo'] as $key => $value) {
        
printf("SendTo[%s] = %s\n<br>"$key$value);
    }
    
$sql sprintf("UPDATE members SET sendTo=1 WHERE id in (%s);"join(', 'array_keys($_POST['sendTo'])));
    print 
$sql;
  }
?>
<html>
<head>
<title>Sample Sendto</title>
</head>
<body>
<form name="test" id="test" action="sendto.php" method="post">
0<input name="sendTo[0]" id="sendTo[0]" type="checkbox">
1<input name="sendTo[1]" id="sendTo[1]" type="checkbox">
2<input name="sendTo[2]" id="sendTo[2]" type="checkbox">
4<input name="sendTo[4]" id="sendTo[4]" type="checkbox">
8<input name="sendTo[8]" id="sendTo[8]" type="checkbox">
<br>
<input id="submitButton" type="submit" value="submit">
</form>
</body>
</html>
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #4  
Old July 13th, 2004, 12:16 AM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
I wonder if this ever got resolved???

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Updating Values with 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 4 hosted by Hostway