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 April 7th, 2004, 03:16 AM
Alicia Alicia is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 117 Alicia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 29 sec
Reputation Power: 6
delete multiple records

Hi guys,

I am trying to pass multiple values by using a variable from one file to another.. in one file, i set all checkboxes with variable name 'remove' (use while loop).. each check box comes with differen value.. when the user check more than one check box, it will delete the records in db according to the value of the checkbox..

in short, i want my system to perform a task like what yahoo mailbox can do.. when we check the checkbox next to the email that u wanna delete and then click on remove button.. after that, the email selected will be removed..

this is the code where i used to capture the values of 'remove' being pass from other file ... but it doesn't seem to work coz this error occured
Invalid argument supplied for foreach()

my code:
if (isset($_POST['remove']))
{
$total = count($_POST['remove']);
$removed = 0;

if ($total == 0)
{
die('You did not select any records...');
}
else
{
foreach ($_POST['remove'] as $val)
{
$sql = "DELETE FROM transaction
WHERE code = '$val'";
$res = mysql_query($sql);

if (mysql_affected_rows() > 0)
{
$removed++;
}
}


i am wondering is it i can not use same variable for the checkbox that with different values ??? or could u guys give me an idea where i can get a reference how to perform this kind of task ??

please advise.

Reply With Quote
  #2  
Old April 7th, 2004, 05:12 PM
wink wink is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 4 wink User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yes, you can use same name with different values, but. it has to be like this :

checkbox 1 : name=x[0]
checkbox 2 : name=x[1]
etc....

on PHP
$val = $_POST['x']
$val[0] <= will print x[0] value
$val[1] <= will print x[1] value

Hope that help

wink,
Less than $1 / month web hosting
URL

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > delete multiple records


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 5 hosted by Hostway
Stay green...Green IT