[thelist] RE: Arrays and Multiple Select?
Joe Crawford
jcrawford at avencom.com
Tue Oct 9 15:48:08 CDT 2001
"McAtee, Malcolm" wrote:
> Sorry for posting this again, but any help would be appreciated.
Sure thing ...
> I still seem unable to pass these form.values in the multiple select.
They're getting passed ... don't worry, you're just not reading them,
looks like --
> i am not a php programmer but these seems conceptually sound to me.
> Am I making a syntax error? do I need PHP4?(I am on 3) do I need to rename
> my file extensions to .php3?
Consult your sysadmin for that informaton - simple test is to make a
simple helloworld.php and a helloworld.php3 file and upload with:
<?php echo "hello world"; ?>
And see what you get in each case.
Now, on to your code:
> form.php
> <select name="Type_of_Event[]" size="3" multiple>
<many snips>
>
> print "Type_of_Event:<br>\n";
> foreach($Type_of_Event as $event)
> {
> print "$event<br>\n";
> }
I'm not sure about that foreach syntax. I would use a for loop like so:
for($i=0;$i<count($Type_of_Event);++$i){
print $Type_of_Event[$i];
print "\n";
};
See also:
http://www.php.net/manual/en/function.count.php
http://www.php.net/manual/en/ref.array.php
http://www.php.net/manual/en/control-structures.foreach.php
Hope that helps -- I made a test page - but only internally -- check the
code at the end of this note and save as foo.php
- Joe <http://artlung.com/>
--
................... Joe Crawford \\ Web Design & Development
..... mailto:jcrawford at avencom.com \\ http://www.avencom.com
.... San Diego \\ CA \\ USA \\ AVENCOM: Set Your Sites Higher
<!-- code begins here, save as foo.php -->
<pre>
<form action="foo.php" method="get">
====================================================================
<select name="Type_of_Event[]" size="3" multiple>
<option value="Dinner">Dinner</option>
<option value="Lunch">Lunch</option>
<option value="Breakfast">Breakfast</option>
<option value="Cocktail Reception">Cocktail Reception</option>
<option value="Meeting">Meeting</option>
<option value="Other">Other</option>
</select>
<input type="submit">
====================================================================
</form>
<b>Type_of_Event:</b>
<?
/* php actually begins here */
for($i=0;$i<count($Type_of_Event);++$i){
print $Type_of_Event[$i];
print "\n";
};
?>
</pre>
<!-- code ends here, save as foo.php -->
More information about the thelist
mailing list