Re: [PHP-DB] Checkboxes to gather rows to delete

2003-02-24 Thread 1LT John W. Holmes
 I have a mysql database with a table using one column as a primary key.
 (rowID). On a php page I use a query to  list all of the rows of the table
 and have a checkbox beside each  row that should be used to check if you
 would like to delete this row. Can someone give me an example using post
 to pull the boxes that need to be deleted.

Easy one.. :)

Make sure your checkboxes have the rowID as their value, then you can simply
do this:

$query = DELETE FROM table WHERE rowID IN ( .
implode(',',$_POST['checkboxes']) . );

and run that query.

You'll end up with something that looks like this:

DELETE FROM table WHERE rowID IN (1,2,3,4,5)

where the numbers will come from only the checkboxes that you selected.

---John Holmes...


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Checkboxes to gather rows to delete

2003-02-24 Thread Mathieu Dumoulin
It is wrong to use that way of doing it John, cause this will delete ALL
lines that where printed with a checkbox
And also, if you are using a old version of PHP with register globals OFF,
the _POST array will not be available

Mathieu Dumoulin

1lt John W. Holmes [EMAIL PROTECTED] a écrit dans le message de
news: [EMAIL PROTECTED]
  I have a mysql database with a table using one column as a primary key.
  (rowID). On a php page I use a query to  list all of the rows of the
table
  and have a checkbox beside each  row that should be used to check if you
  would like to delete this row. Can someone give me an example using post
  to pull the boxes that need to be deleted.

 Easy one.. :)

 Make sure your checkboxes have the rowID as their value, then you can
simply
 do this:

 $query = DELETE FROM table WHERE rowID IN ( .
 implode(',',$_POST['checkboxes']) . );

 and run that query.

 You'll end up with something that looks like this:

 DELETE FROM table WHERE rowID IN (1,2,3,4,5)

 where the numbers will come from only the checkboxes that you selected.

 ---John Holmes...




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Checkboxes to gather rows to delete

2003-02-24 Thread George Pitcher
Hi all,

Can I raise a point of principle here.

My databases never have records deleted - instead they are marked as being
deleted in a status field. That way, they are always there for reference.

Unless you are running a system that needs the space or has extremely high
turnover of deleted records, this makes sesne.

Just my 2c.

George in Oxford

 -Original Message-
 From: Mathieu Dumoulin [mailto:[EMAIL PROTECTED]
 Sent: 24 February 2003 3:49 pm
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP-DB] Checkboxes to gather rows to delete


 It is wrong to use that way of doing it John, cause this will delete ALL
 lines that where printed with a checkbox
 And also, if you are using a old version of PHP with register globals OFF,
 the _POST array will not be available

 Mathieu Dumoulin

 1lt John W. Holmes [EMAIL PROTECTED] a écrit dans le message de
 news: [EMAIL PROTECTED]
   I have a mysql database with a table using one column as a
 primary key.
   (rowID). On a php page I use a query to  list all of the rows of the
 table
   and have a checkbox beside each  row that should be used to
 check if you
   would like to delete this row. Can someone give me an example
 using post
   to pull the boxes that need to be deleted.
 
  Easy one.. :)
 
  Make sure your checkboxes have the rowID as their value, then you can
 simply
  do this:
 
  $query = DELETE FROM table WHERE rowID IN ( .
  implode(',',$_POST['checkboxes']) . );
 
  and run that query.
 
  You'll end up with something that looks like this:
 
  DELETE FROM table WHERE rowID IN (1,2,3,4,5)
 
  where the numbers will come from only the checkboxes that you selected.
 
  ---John Holmes...
 



 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Checkboxes to gather rows to delete

2003-02-24 Thread Lewis Watson
I appreciate all of the quick replies. I do have globals off. Currently, I
have the values for each ID being returned in a array Array ( [0] =
101 [1] = 201 )  where 101 and 201 were the id's of the rows I checked. I
have to say I like the way of doing it that Mathieu has shown using the
explode function.
Thanks again.
Lewis


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Checkboxes to gather rows to delete

2003-02-24 Thread 1LT John W. Holmes
 I appreciate all of the quick replies. I do have globals off. Currently, I
 have the values for each ID being returned in a array Array ( [0] =
 101 [1] = 201 )  where 101 and 201 were the id's of the rows I checked. I
 have to say I like the way of doing it that Mathieu has shown using the
 explode function.
 Thanks again.
 Lewis

You already have an array of IDs you want to delete. Explode is for making
arrays, so what would you use it on? That doesn't make sense.

$query = DELETE FROM table WHERE rowID IN ( .
implode(',',$_POST['id_array']) . );

is the most efficient, easiest solution, but use whatever you understand.

---John Holmes...


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Checkboxes to gather rows to delete

2003-02-24 Thread Lewis Watson
Thats just it. I am just not sure what to do with the array before my
delete from query now that I have it :-)
Thanks...
Lewis


- Original Message -
From: 1LT John W. Holmes [EMAIL PROTECTED]
To: Lewis Watson [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Monday, February 24, 2003 10:13 AM
Subject: Re: [PHP-DB] Checkboxes to gather rows to delete


  I appreciate all of the quick replies. I do have globals off.
Currently, I
  have the values for each ID being returned in a array Array ( [0]
=
  101 [1] = 201 )  where 101 and 201 were the id's of the rows I
checked. I
  have to say I like the way of doing it that Mathieu has shown using
the
  explode function.
  Thanks again.
  Lewis

 You already have an array of IDs you want to delete. Explode is for
making
 arrays, so what would you use it on? That doesn't make sense.

 $query = DELETE FROM table WHERE rowID IN ( .
 implode(',',$_POST['id_array']) . );

 is the most efficient, easiest solution, but use whatever you
understand.

 ---John Holmes...



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Checkboxes to gather rows to delete

2003-02-24 Thread 1LT John W. Holmes
 Thats just it. I am just not sure what to do with the array before my
 delete from query now that I have it :-)
 Thanks...
 Lewis

You don't have to do anything with it, just throw it into the line that I
gave you. Show the code you have now and someone can help you put it all
together.

---John Holmes...

 - Original Message -
 From: 1LT John W. Holmes [EMAIL PROTECTED]
 To: Lewis Watson [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Monday, February 24, 2003 10:13 AM
 Subject: Re: [PHP-DB] Checkboxes to gather rows to delete


   I appreciate all of the quick replies. I do have globals off.
 Currently, I
   have the values for each ID being returned in a array Array ( [0]
 =
   101 [1] = 201 )  where 101 and 201 were the id's of the rows I
 checked. I
   have to say I like the way of doing it that Mathieu has shown using
 the
   explode function.
   Thanks again.
   Lewis
 
  You already have an array of IDs you want to delete. Explode is for
 making
  arrays, so what would you use it on? That doesn't make sense.
 
  $query = DELETE FROM table WHERE rowID IN ( .
  implode(',',$_POST['id_array']) . );
 
  is the most efficient, easiest solution, but use whatever you
 understand.
 
  ---John Holmes...
 


 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Checkboxes to gather rows to delete

2003-02-24 Thread Lewis Watson
Thanks. The below code returns each ID in an array like so...
Array ( [0] =101 [1] = 201 ). Thanks for the help!
Lewis

$teacherID = $_POST[teacherID];
$deleteID = $_POST[deleteID];

if(isset($delete_teacher)) {
  This is where I should loop through checking for the chosen ones to
delete.

}

form action= method=POST
 print input type=checkbox name=\deleteID[]\
value=\$row[teacherID]\;
 print input type=submit  name=\delete_teacher\  value=\Delete the
Checked Teachers\;


- Original Message -
From: 1LT John W. Holmes [EMAIL PROTECTED]
To: Lewis Watson [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Monday, February 24, 2003 10:21 AM
Subject: Re: [PHP-DB] Checkboxes to gather rows to delete


  Thats just it. I am just not sure what to do with the array before my
  delete from query now that I have it :-)
  Thanks...
  Lewis

 You don't have to do anything with it, just throw it into the line that
I
 gave you. Show the code you have now and someone can help you put it all
 together.

 ---John Holmes...

  - Original Message -
  From: 1LT John W. Holmes [EMAIL PROTECTED]
  To: Lewis Watson [EMAIL PROTECTED]; [EMAIL PROTECTED]
  Sent: Monday, February 24, 2003 10:13 AM
  Subject: Re: [PHP-DB] Checkboxes to gather rows to delete
 
 
I appreciate all of the quick replies. I do have globals off.
  Currently, I
have the values for each ID being returned in a array Array
( [0]
  =
101 [1] = 201 )  where 101 and 201 were the id's of the rows I
  checked. I
have to say I like the way of doing it that Mathieu has shown
using
  the
explode function.
Thanks again.
Lewis
  
   You already have an array of IDs you want to delete. Explode is for
  making
   arrays, so what would you use it on? That doesn't make sense.
  
   $query = DELETE FROM table WHERE rowID IN ( .
   implode(',',$_POST['id_array']) . );
  
   is the most efficient, easiest solution, but use whatever you
  understand.
  
   ---John Holmes...
  
 
 
  --
  PHP Database Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 


 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Checkboxes to gather rows to delete

2003-02-24 Thread Lewis Watson
Hi there,
I have double checked the column namesIts giving me a Warning: Bad
arguments to implode() error
Thanks.
Lewis

- Original Message -
From: 1LT John W. Holmes [EMAIL PROTECTED]
To: Lewis Watson [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Monday, February 24, 2003 10:36 AM
Subject: Re: [PHP-DB] Checkboxes to gather rows to delete


  Thanks. The below code returns each ID in an array like so...
  Array ( [0] =101 [1] = 201 ). Thanks for the help!
  Lewis
 
  $teacherID = $_POST[teacherID];
  $deleteID = $_POST[deleteID];
 
  if(isset($delete_teacher)) {
This is where I should loop through checking for the chosen ones
to
  delete.

 $query = DELETE FROM table WHERE teacherID IN ( .
implode(',',$deleteID) .
 );
 mysql_query($query);

  }
 
  form action= method=POST
   print input type=checkbox name=\deleteID[]\
  value=\$row[teacherID]\;
   print input type=submit  name=\delete_teacher\  value=\Delete
the
  Checked Teachers\;

 Make sure the column names are correct, but that's it.

 ---John Holmes...




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Checkboxes to gather rows to delete

2003-02-24 Thread Jason Wong
On Monday 24 February 2003 23:57, George Pitcher wrote:

 Can I raise a point of principle here.

 My databases never have records deleted - instead they are marked as being
 deleted in a status field. That way, they are always there for reference.

 Unless you are running a system that needs the space or has extremely high
 turnover of deleted records, this makes sesne.

Better still, setup parallel tables and move deleted records over. That way 
you'll save cluttering up the main tables.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-db
--
/*
A diplomat's life consists of three things: protocol, Geritol, and alcohol.
-- Adlai Stevenson
*/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Checkboxes to gather rows to delete

2003-02-24 Thread John W. Holmes
 Hi there,
 I have double checked the column namesIts giving me a Warning: Bad
 arguments to implode() error
 Thanks.
 Lewis

What's the code you're using? Are you sure $deleteID is an array at the
point you call implode()? Are you sure it's available in the current
scope at the point you call implode()?

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/

 
 - Original Message -
 From: 1LT John W. Holmes [EMAIL PROTECTED]
 To: Lewis Watson [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Monday, February 24, 2003 10:36 AM
 Subject: Re: [PHP-DB] Checkboxes to gather rows to delete
 
 
   Thanks. The below code returns each ID in an array like so...
   Array ( [0] =101 [1] = 201 ). Thanks for the help!
   Lewis
  
   $teacherID = $_POST[teacherID];
   $deleteID = $_POST[deleteID];
  
   if(isset($delete_teacher)) {
 This is where I should loop through checking for the chosen
ones
 to
   delete.
 
  $query = DELETE FROM table WHERE teacherID IN ( .
 implode(',',$deleteID) .
  );
  mysql_query($query);
 
   }
  
   form action= method=POST
print input type=checkbox name=\deleteID[]\
   value=\$row[teacherID]\;
print input type=submit  name=\delete_teacher\
value=\Delete
 the
   Checked Teachers\;
 
  Make sure the column names are correct, but that's it.
 
  ---John Holmes...
 
 
 
 
 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Checkboxes to gather rows to delete

2003-02-24 Thread Lewis Watson
I think the problem is that I need to put the array into a comma delimited
group
Lewis

- Original Message -
From: John W. Holmes [EMAIL PROTECTED]
To: 'Lewis Watson' [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Monday, February 24, 2003 11:09 AM
Subject: RE: [PHP-DB] Checkboxes to gather rows to delete


  Hi there,
  I have double checked the column namesIts giving me a Warning: Bad
  arguments to implode() error
  Thanks.
  Lewis

 What's the code you're using? Are you sure $deleteID is an array at the
 point you call implode()? Are you sure it's available in the current
 scope at the point you call implode()?

 ---John W. Holmes...

 PHP Architect - A monthly magazine for PHP Professionals. Get your copy
 today. http://www.phparch.com/

 
  - Original Message -
  From: 1LT John W. Holmes [EMAIL PROTECTED]
  To: Lewis Watson [EMAIL PROTECTED]; [EMAIL PROTECTED]
  Sent: Monday, February 24, 2003 10:36 AM
  Subject: Re: [PHP-DB] Checkboxes to gather rows to delete
 
 
Thanks. The below code returns each ID in an array like so...
Array ( [0] =101 [1] = 201 ). Thanks for the help!
Lewis
   
$teacherID = $_POST[teacherID];
$deleteID = $_POST[deleteID];
   
if(isset($delete_teacher)) {
  This is where I should loop through checking for the chosen
 ones
  to
delete.
  
   $query = DELETE FROM table WHERE teacherID IN ( .
  implode(',',$deleteID) .
   );
   mysql_query($query);
  
}
   
form action= method=POST
 print input type=checkbox name=\deleteID[]\
value=\$row[teacherID]\;
 print input type=submit  name=\delete_teacher\
 value=\Delete
  the
Checked Teachers\;
  
   Make sure the column names are correct, but that's it.
  
   ---John Holmes...
  
  
 
 
  --
  PHP Database Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php




 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Checkboxes to gather rows to delete

2003-02-24 Thread 1LT John W. Holmes
 I think the problem is that I need to put the array into a comma delimited
 group
 Lewis

U... that's what IMPLODE does. It will take the array and turn it into a
comma separated list. Your having a problem because you're not passing an
array when you think you are.

---John Holmes...

 - Original Message -
 From: John W. Holmes [EMAIL PROTECTED]
 To: 'Lewis Watson' [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Monday, February 24, 2003 11:09 AM
 Subject: RE: [PHP-DB] Checkboxes to gather rows to delete


   Hi there,
   I have double checked the column namesIts giving me a Warning: Bad
   arguments to implode() error
   Thanks.
   Lewis
 
  What's the code you're using? Are you sure $deleteID is an array at the
  point you call implode()? Are you sure it's available in the current
  scope at the point you call implode()?
 
  ---John W. Holmes...
 
  PHP Architect - A monthly magazine for PHP Professionals. Get your copy
  today. http://www.phparch.com/
 
  
   - Original Message -
   From: 1LT John W. Holmes [EMAIL PROTECTED]
   To: Lewis Watson [EMAIL PROTECTED]; [EMAIL PROTECTED]
   Sent: Monday, February 24, 2003 10:36 AM
   Subject: Re: [PHP-DB] Checkboxes to gather rows to delete
  
  
 Thanks. The below code returns each ID in an array like so...
 Array ( [0] =101 [1] = 201 ). Thanks for the help!
 Lewis

 $teacherID = $_POST[teacherID];
 $deleteID = $_POST[deleteID];

 if(isset($delete_teacher)) {
   This is where I should loop through checking for the chosen
  ones
   to
 delete.
   
$query = DELETE FROM table WHERE teacherID IN ( .
   implode(',',$deleteID) .
);
mysql_query($query);
   
 }

 form action= method=POST
  print input type=checkbox name=\deleteID[]\
 value=\$row[teacherID]\;
  print input type=submit  name=\delete_teacher\
  value=\Delete
   the
 Checked Teachers\;
   
Make sure the column names are correct, but that's it.
   
---John Holmes...
   
   
  
  
   --
   PHP Database Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
  --
  PHP Database Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 


 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php