RE: [PHP] Need some advice concerning forms (multi select pulldown) and arrays

2002-05-27 Thread John Holmes

Shouldn't it be

count($_REQUEST['animals'])

and

count($_REQUEST['animals'][2]), etc...

??

---John Holmes...

> -Original Message-
> From: Victor Spång Arthursson [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, May 26, 2002 1:29 PM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: Re: [PHP] Need some advice concerning forms (multi select
> pulldown) and arrays
> 
> Ok, I can't get this right...
> 
> Have the following code:
> 
> 
>$choices = array(1 => 'dog', 2 => 'cat', 3 => 'mouse', 4 =>
'frog');
> 
>   if (is_array($_REQUEST['animals']))
>   {
>   // get the number of selectcases
>   echo "get the number of selectcases: " . count($animals)
.
> "";
> 
>   // get the number of provided selects from select with
name
> "2"
>   echo "get the number of provided selects from select
with name
> \"2\": " . count($animals[2]) . "";
> 
>   // test to print some data
>   echo $animals[2][0]. "";
>   echo $animals[2][1]. "";
>   echo $animals[2][2]. "";
>   echo $animals[2][3]. "";
>   }
>?>
> 
>   
>   dog
>   cat
>   mouse
>   frog
>   
> 
>  
>   dog
>   cat
>   mouse
>   frog
>  
> 
> 
> Why does it not work?
> 
>   // get the number of selectcases
>   echo "get the number of selectcases: " . count($animals)
.
> "";
> 
> This works great
> 
>   // get the number of provided selects from select with
name
> "2"
>   echo "get the number of provided selects from select
with name
> \"2\": " . count($animals[2]) . "";
> 
> But this doesn't...
> 
> Thankful for any help,
> 
> /Victor
> 
> On Sunday, May 26, 2002, at 05:35 PM, John Holmes wrote:
> 
> > You can supply an "whateverID" for the select if you want to.
> >
> > 
> >  > 
> >
> > 
> >  > 
> >
> > etc...
> >
> > That will give you an array $select[] on the processing page. If the
> > selects are multi-selects, you'll have a multidimensional array. The
> > first chosen element in the first select box can be referenced like
this
> >
> > $select[0][0]
> >
> > You can get a count of how many select boxes there are by doing
> >
> > count($select);
> >
> > You can get a count of how many elements were selected within a
select
> > you can do this:
> >
> > count($select[x]);
> >
> > Where x is the number of the select box you want to know about.
> >
> > Confusing, eh?
> >
> > ---John Holmes...
> >
> >> -Original Message-
> >> From: Victor Spång Arthursson [mailto:[EMAIL PROTECTED]]
> >> Sent: Sunday, May 26, 2002 7:44 AM
> >> To: [EMAIL PROTECTED]
> >> Subject: Re: [PHP] Need some advice concerning forms (multi select
> >> pulldown) and arrays
> >>
> >>
> >> On Sunday, May 26, 2002, at 01:14 PM, John Holmes wrote:
> >>
> >>> Just give each select its own name.
> >>
> >> Can't do that, don't know from time to time how many there'll
be
> > And
> >> I've to have some case which iterates on the following page...
> >>
> >>> Or name them all the same followed
> >>> by an [] and you'll end up with a multi-dimensional array if
things
> > go
> >>> right...
> >>
> >> Sounds better - but I've a lot of items and I'ld like to know which
of
> >> the arrays that go to which item... Can I just write
> >> …name=array[whateverid] and then in some way reveal the
whateverid's?
> >>
> >> Sincerely
> >>
> >> Victor
> >
> >



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




Re: [PHP] Need some advice concerning forms (multi select pulldown)and arrays

2002-05-26 Thread Miguel Cruz

On Sun, 26 May 2002, Victor Spång Arthursson wrote:
>   

change this to:

   

>  

and this to:

   

because you want animals[2] and animals[4] to be arrays, not scalar 
values.

miguel


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




Re: [PHP] Need some advice concerning forms (multi select pulldown) and arrays

2002-05-26 Thread Victor Spång Arthursson

Ok, I can't get this right...

Have the following code:

'dog', 2 => 'cat', 3 => 'mouse', 4 => 'frog');

if (is_array($_REQUEST['animals']))
{
// get the number of selectcases
echo "get the number of selectcases: " . count($animals) . "";

// get the number of provided selects from select with name "2"
echo "get the number of provided selects from select with name 
\"2\": " . count($animals[2]) . "";

// test to print some data
echo $animals[2][0]. "";
echo $animals[2][1]. "";
echo $animals[2][2]. "";
echo $animals[2][3]. "";
}
   ?>


dog
cat
mouse
frog


 
dog
cat
mouse
frog
 


Why does it not work?

// get the number of selectcases
echo "get the number of selectcases: " . count($animals) . "";

This works great

// get the number of provided selects from select with name "2"
echo "get the number of provided selects from select with name 
\"2\": " . count($animals[2]) . "";

But this doesn't...

Thankful for any help,

/Victor

On Sunday, May 26, 2002, at 05:35 PM, John Holmes wrote:

> You can supply an "whateverID" for the select if you want to.
>
> 
>  
>
> 
>  
>
> etc...
>
> That will give you an array $select[] on the processing page. If the
> selects are multi-selects, you'll have a multidimensional array. The
> first chosen element in the first select box can be referenced like this
>
> $select[0][0]
>
> You can get a count of how many select boxes there are by doing
>
> count($select);
>
> You can get a count of how many elements were selected within a select
> you can do this:
>
> count($select[x]);
>
> Where x is the number of the select box you want to know about.
>
> Confusing, eh?
>
> ---John Holmes...
>
>> -Original Message-
>> From: Victor Spång Arthursson [mailto:[EMAIL PROTECTED]]
>> Sent: Sunday, May 26, 2002 7:44 AM
>> To: [EMAIL PROTECTED]
>> Subject: Re: [PHP] Need some advice concerning forms (multi select
>> pulldown) and arrays
>>
>>
>> On Sunday, May 26, 2002, at 01:14 PM, John Holmes wrote:
>>
>>> Just give each select its own name.
>>
>> Can't do that, don't know from time to time how many there'll be
> And
>> I've to have some case which iterates on the following page...
>>
>>> Or name them all the same followed
>>> by an [] and you'll end up with a multi-dimensional array if things
> go
>>> right...
>>
>> Sounds better - but I've a lot of items and I'ld like to know which of
>> the arrays that go to which item... Can I just write
>> …name=array[whateverid] and then in some way reveal the whateverid's?
>>
>> Sincerely
>>
>> Victor
>
>


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




Re: [PHP] Need some advice concerning forms (multi select pulldown) and arrays

2002-05-26 Thread Victor Spång Arthursson


On Sunday, May 26, 2002, at 01:14 PM, John Holmes wrote:

> Just give each select its own name.

Can't do that, don't know from time to time how many there'll be And 
I've to have some case which iterates on the following page...

> Or name them all the same followed
> by an [] and you'll end up with a multi-dimensional array if things go
> right...

Sounds better - but I've a lot of items and I'ld like to know which of 
the arrays that go to which item... Can I just write 
…name=array[whateverid] and then in some way reveal the whateverid's?

Sincerely

Victor


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




RE: [PHP] Need some advice concerning forms (multi select pulldown) and arrays

2002-05-26 Thread John Holmes

Just give each select its own name. Or name them all the same followed
by an [] and you'll end up with a multi-dimensional array if things go
right...


...


---John Holmes...

> -Original Message-
> From: Victor Spång Arthursson [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, May 26, 2002 5:49 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] Need some advice concerning forms (multi select
> pulldown) and arrays
> 
> Hello and thanks for your fast answer!
> 
> I'ld like to know if there is any possibility to distinguish the
selects
> if I've multiple multiple selects, that is, more than one on the same
> page? What I'm loooking for is the possibility to have an unknown
number
> of multiple selects on the same page
> 
> Is it possible? Anyone who can describe how to do this or provide a
link
> to some tutorial? And also, where in the manual can I read about this?
> 
> Sincerely,
> 
> Victor
> 
> On lördag, maj 25, 2002, at 08:59 , Miguel Cruz wrote:
> 
> > Have a play with this little program - it should demonstrate all of
the
> > things you'd want to do with getting data in and out of mult
selects. If
> > it doesn't work, you may have an older version of PHP - in that
case,
> > change "$_REQUEST" to "$HTTP_POST_VARS" and "$_SERVER['PHP_SELF']"
to
> > "$PHP_SELF".
> >
> > ---
> >>
> >   $choices = array(1 => 'dog', 2 => 'cat', 3 => 'mouse', 4 =>
'frog');
> >
> >   if (is_array($_REQUEST['animals']))
> >   {
> > print 'You chose:';
> > foreach ($_REQUEST['animals'] as $animal_id)
> >   print "{$choices[$animal_id]}";
> > print '';
> >   }
> >
> >   ?>
> >>
> >   foreach ($choices as $id => $name)
> > print ' >   . (in_array($id, $_REQUEST['animals']) ? 'selected ' : '')
> >   . "value='$id'>$name";
> >
> >   ?>
> >
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



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




Re: [PHP] Need some advice concerning forms (multi select pulldown) and arrays

2002-05-26 Thread Victor Spång Arthursson

Hello and thanks for your fast answer!

I'ld like to know if there is any possibility to distinguish the selects 
if I've multiple multiple selects, that is, more than one on the same 
page? What I'm loooking for is the possibility to have an unknown number 
of multiple selects on the same page

Is it possible? Anyone who can describe how to do this or provide a link 
to some tutorial? And also, where in the manual can I read about this?

Sincerely,

Victor

On lördag, maj 25, 2002, at 08:59 , Miguel Cruz wrote:

> Have a play with this little program - it should demonstrate all of the
> things you'd want to do with getting data in and out of mult selects. If
> it doesn't work, you may have an older version of PHP - in that case,
> change "$_REQUEST" to "$HTTP_POST_VARS" and "$_SERVER['PHP_SELF']" to
> "$PHP_SELF".
>
> ---
>   
>   $choices = array(1 => 'dog', 2 => 'cat', 3 => 'mouse', 4 => 'frog');
>
>   if (is_array($_REQUEST['animals']))
>   {
> print 'You chose:';
> foreach ($_REQUEST['animals'] as $animal_id)
>   print "{$choices[$animal_id]}";
> print '';
>   }
>
>   ?>
>   
>   foreach ($choices as $id => $name)
> print '   . (in_array($id, $_REQUEST['animals']) ? 'selected ' : '')
>   . "value='$id'>$name";
>
>   ?>
>


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




Re: [PHP] Need some advice concerning forms (multi select pulldown)and arrays

2002-05-25 Thread Miguel Cruz

Oops. I actually tried running it (cleverly waiting until after I posted 
it to the list) and I see that there are some warnings in the event that 
nothing has been selected (due to in_array operating on an undefined 
variable). Don't worry about them. Or change that last foreach clause to 
look like this:

  foreach ($choices as $id => $name)
print '$name";

(I added an is_array to make sure we don't send a null value as the second 
argument to in_array).

miguel

On Sat, 25 May 2002, Miguel Cruz wrote:
> Have a play with this little program - it should demonstrate all of the
> things you'd want to do with getting data in and out of mult selects. If
> it doesn't work, you may have an older version of PHP - in that case,
> change "$_REQUEST" to "$HTTP_POST_VARS" and "$_SERVER['PHP_SELF']" to
> "$PHP_SELF".
> 
> ---
>
>   $choices = array(1 => 'dog', 2 => 'cat', 3 => 'mouse', 4 => 'frog');
> 
>   if (is_array($_REQUEST['animals']))
>   {   
> print 'You chose:';
> foreach ($_REQUEST['animals'] as $animal_id)  
>   print "{$choices[$animal_id]}";
> print '';
>   }
> 
>   ?>
>
>   foreach ($choices as $id => $name)
> print '   . (in_array($id, $_REQUEST['animals']) ? 'selected ' : '') 
>   . "value='$id'>$name";
> 
>   ?>
> 
> ---
> miguel
> 
> 
> 


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




Re: [PHP] Need some advice concerning forms (multi select pulldown)and arrays

2002-05-25 Thread Miguel Cruz

On Sat, 25 May 2002, Victor Spång Arthursson wrote:
> I know it's possible to use arrays in combination with forms, but I need
> some advice about where to find some information/tutorial concerning how
> to use arrays together with "multi-select-tags"...

Have a play with this little program - it should demonstrate all of the
things you'd want to do with getting data in and out of mult selects. If
it doesn't work, you may have an older version of PHP - in that case,
change "$_REQUEST" to "$HTTP_POST_VARS" and "$_SERVER['PHP_SELF']" to
"$PHP_SELF".

---
   'dog', 2 => 'cat', 3 => 'mouse', 4 => 'frog');

  if (is_array($_REQUEST['animals']))
  {   
print 'You chose:';
foreach ($_REQUEST['animals'] as $animal_id)  
  print "{$choices[$animal_id]}";
print '';
  }

  ?>
   $name)
print '$name";

  ?>

---
miguel


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