Re: [PHP-DB] checkboxes and loops

2004-03-29 Thread John W. Holmes
matthew perry wrote:


$counter++;

*Bad solution 2 (doesn't work)***
$counter = 1;
while (<>)
{
if ($box . $counter == 'delete')   <>
$counter++;
}
***
if(${$box . $counter} == 'delete')

However, like someone else said, if you named your checkboxes as box[1], 
box[2], etc, then you'd have a nice $_POST['box'] array that you could 
loop through.

foreach($_POST['box'] as $count => $value)
{ do_whatever($count); }
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

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


RE: [PHP-DB] checkboxes and loops

2004-03-29 Thread Duane Lakoduk
I am relatively new with PHP, but have done this many times with ASP.
First, I would not assign the counter value to the checkbox as you are now.
Use the ID (identity) value from the database for the applicant record
instead.  Since ONLY the checkboxes that are checked will be submitted, you
can just loop through the submitted checkbox values and perform a 'delete',
or 'whatever' on each submitted record.  Or, use: "...WHERE IN (id1, id2,
..., idN)" in your DELETE statement.

Duane



> -Original Message-
> From: matthew perry [mailto:[EMAIL PROTECTED]
> Sent: Sunday, March 28, 2004 11:45 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] checkboxes and loops
>
>
> OK lets see if I can figure out how to ask this:
>
> I am setting up a system for my company to filter through employee
> applications.  Most of the applications do not fit the criteria and I
> want to allow my bosses a checkbox to the right of them which
> they can
> check or uncheck to remove an applicant.
> So I run a loop that generates a bunch of check boxes with the name
> box1, box2, box3... by running a loop that runs this and increments
> counter every time:
> {
>  = "delete">
> $counter++;
> }
>
> But when I try to create my query that updates the table I have a
> problem generating these variable again by referring to them
> indirectly:
>
> *Bad solution 1 (to much work)***
> if ($box1 == 'delete')   <>
> if ($box2 == 'delete')  <>
> if ($box3 == 'delete')  <>
> if ($box4 == 'delete')  <>
> if ($box5 == 'delete')  <>
> if ($box6 == 'delete')  <>
> ***
>
> *Bad solution 2 (doesn't work)***
> $counter = 1;
> while (<>)
> {
> if ($box . $counter == 'delete')   <>
> $counter++;
> }
> ***
>
> How do I get around this problem?
> Hopefully someone understands what I am trying to say.
>
> Matt
>
> --
> 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 and loops

2004-03-28 Thread Mikhail U. Petrov
Hi!
I think you should rename checkboxes to box[1], box[2] etc.
So you will get an array $_POST["box"]. I think it will be better.
Best wishes,
Mikhail U. Petrov,
PHP-programmer



Hello matthew,

Monday, March 29, 2004, 9:45:28 AM, you wrote:

mp> OK lets see if I can figure out how to ask this:

mp> I am setting up a system for my company to filter through employee 
mp> applications.  Most of the applications do not fit the criteria and I 
mp> want to allow my bosses a checkbox to the right of them which they can 
mp> check or uncheck to remove an applicant.
mp> So I run a loop that generates a bunch of check boxes with the name 
mp> box1, box2, box3... by running a loop that runs this and increments 
mp> counter every time:
mp> {
mp> 
mp> $counter++;
mp> }

mp> But when I try to create my query that updates the table I have a 
mp> problem generating these variable again by referring to them indirectly:

mp> *Bad solution 1 (to much work)***
mp> if ($box1 == 'delete')   <>
mp> if ($box2 == 'delete')  <>
mp> if ($box3 == 'delete')  <>
mp> if ($box4 == 'delete')  <>
mp> if ($box5 == 'delete')  <>
mp> if ($box6 == 'delete')  <>
mp> ***

mp> *Bad solution 2 (doesn't work)***
mp> $counter = 1;
mp> while (<>)
mp> {
mp> if ($box . $counter == 'delete')   <>
mp> $counter++;
mp> }
mp> ***

mp> How do I get around this problem?
mp> Hopefully someone understands what I am trying to say.

mp> Matt

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