SearchSearch   

array wizardry

 
   Webmaster Forums (Home) -> PHP MySQL RSS
Next:  array wizardry  
Author Message
strawberry

External


Since: Apr 20, 2007
Posts: 21



(Msg. 1) Posted: Tue Dec 16, 2008 2:13 pm
Post subject: array wizardry
Archived from groups: alt>php>sql (more info?)

Hi all. Can anyone help me out here?

A script like this...

echo "<form action='processform.php' method='POST'>\n";
echo "<select name='name[sphere]'>\n";
echo "<option value='colour[] '>Select One</option>\n";
echo "<option value='colour[red]'>1</option>\n";
echo "<option value='colour[green]'>2</option>\n";
echo "<option value='colour[blue]'>3</option>\n";
echo "</select><br>\n";
echo "<select name='name[cube]'>\n";
echo "<option value='colour[]'>Select One</option>\n";
echo "<option value='colour[red]'>1</option>\n";
echo "<option value='colour[green]'>2</option>\n";
echo "<option value='colour[blue]'>3</option>\n";
echo "</select><br>\n";
echo "<input type='submit' value = 'go'>\n";
echo "</form>\n";

can produce an array like this...

$_POST:
Array
(
[name] => Array
(
[sphere] => colour[red]
[cube] => colour[green]
)

)

but I guess I'm after an array more like this...

$_POST:
Array
(
[0] => Array
(
[primitive] => sphere
[colour] => red
)

[1] => Array
(
[primitive] => sphere
[colour] => green
)

)

I suspect that this can be done by simply revising the form, without
the need for any additional post-processing.

Going one step further, I'd really like values to passed to the array
ONLY if a value other than the default is selected, but I guess I can
just pass all the values and then use a loop to filter the results.

Any thoughts?
Back to top
Display posts from previous:   
       Webmaster Forums (Home) -> PHP MySQL
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum