Jump to content


Photo

array problem


  • Please log in to reply
2 replies to this topic

#1 Gaia

Gaia
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts
  • LocationCanada

Posted 03 May 2006 - 10:47 PM

Hi,

I have a form that is submitting multiple checkboxes, which when submitted turns into an array.

So my $_POST['option'] turns into a foreach.

<?php

$options = $_POST['option'];

foreach ( $options AS $foo ) {

        $new_options .= 'Something: '.$foo.' &nbsp;';
}

?>

The probem is when i submit it to a database the word Array gets stuck to the first option. so say the $options resulted in 3 check boxes being marked, option1, option2, and option3.

The output would be...

ArraySometing: option1 Something: option2 Something: option3

How do i fix that?

Thanks.

#2 judeddokoinu

judeddokoinu
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 03 May 2006 - 11:24 PM

$options is an array?


Do something like:
<?php

// do a loop on this, most likely...
$options[0] = $_POST['option1'];
$options[1] = $_POST['option2'];


// get the values and store as a string.
foreach ( $options AS $key=>$value )
{
        $new_options .= 'Something: '.$value.' &nbsp;';
}

?>


#3 KrisNz

KrisNz
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts
  • LocationAuckland, New Zealand

Posted 04 May 2006 - 01:31 AM


foreach($options as $array)
{
  foreach($array as $value)
  {
    echo $value;
  }
}






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users