On 20 Nov 2008, at 14:37, Terion Miller wrote:
I currently have it like this:
<select name="BannerSize">

if you've got it working don't change it :)

but to explain:

it is possible to send through an array of data from a form, to do this you place multiple elements with the same name followed by [] in the form..
so
<select name="BannerSize[]"> .. (our first select)
<select name="BannerSize[]"> ... (our second select)

when you do this php will recieve the BannerSize as an array.. so in the above scenario
$_POST['BannerSize'] will contain an array as such:
array(
  0 => "300x250", #whatever was chosen in the first select
  0 => "88x31-300x250" #whatever was chosen in the second select
);

now in the script you originally posted, php was using implode($_POST['BannerSize'] , ',' ); this function was basically taking the array values and combining them together as a single string.

the problem was that if you're form had <select name="BannerSize"> (no brackets) then php didn't receive and array of info in $_POST['BannerSize'] - and thus when it tried to implode the array, it broke, as there wasn't an array within :)

now, most got confused because most people write implode with the parameters the other way around, and they thought that was the error, so kind of confused things. [and because you posted it about 5 times under different names which didn't help ;)]

in short:
if you were using <select name="BannerSize[]"> 's then you'd be wanting to implode the data as it's an array you're recieving if you're using <select name="BannerSize"> as you currently are, then you can forget about all the implode etc.

the ideal fix would have been to make the php code accept either and detect if it was an array or not being passed by replacing the original code:

if (isset($_POST['BannerSize'])){$BannerSize =
implode($_POST['BannerSize'],',');} else {$BannerSize = "";}

with this new code:

if (isset($_POST['BannerSize'])) {
 if(is_array($_POST['BannerSize']) ) {
  $BannerSize = implode(',', $_POST['BannerSize']); //in right order..
 } else {
  $BannerSize = $_POST['BannerSize'];
 }
} else {
 $BannerSize = "";
}

which first checks if banner size has been sent at all,
if it has is it an array? [if yes implode it, if not just pick up the value sent]

hope that helps!

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

Reply via email to