|
|
|
well, it may not be the most elegant method and I'd sure appreciate any
optimizations/suggestions, but it does seem to work. The part that is really bunk is that you
have to pass in the $sel array again in the selectBox() because of the whole global/local issue
[that took me a while to figure out]... is there a better way to achieve this same thing?
--------------------- snip -----------------------
<H2>Using multiple select v2.0</H2>
by <A HREF="http://daevid.com" TARGET="daevid">Daevid Vincent</A>
<?php
function inList($needle, $haystack)
{
while (list($k, $v) = each($haystack))
{
if ($needle == $v) return true;
}
return false;
}
function selectBox($size, $name, $matchArray)
{
echo "<select multiple name='".$name."[]' size='".$size."'>\n";
for ($x = 0; $x < 5; $x++)
{
echo "\t<option value='key".$x."'";
if (inList("key".$x, $matchArray)) echo " SELECTED";
echo ">Value ".$x."\n";
}
echo "</select>";
} //selectBox()
////////////////////////////////////////////////////////////////////////
$num_selected = count($sel);
print "<P>Number of Values selected: $num_selected<p>\n";
if ($num_selected)
{
echo "<P>while list version<BR>\n";
while (list($k, $v) = each($sel))
{ echo "sel[".$k."] == ".$v."<BR>\n"; }
}
?>
<form method="post">
<?php selectBox(6,sel,$sel); ?>
<br>
<input type=submit value="Submit">
</form>
</BODY></HTML> |
|
| PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | Alternating background color for HTML table rows Categories : PHP, Databases, MySQL, HTML and PHP | | | Constantly refresh your PHP/HTML page data. Categories : PHP, HTML and PHP, Sybase | | | background music script for random notes in a frame Categories : PHP, Content Management, HTML and PHP | | | A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL | | | Random Image Display Categories : PHP, Filesystem, Graphics, HTML and PHP | | | PhpView 0.1 - simple php viewer, using temporary files and frames.
Categories : PHP, PHP Options and Info, Debugging, HTML and PHP | | | Automatically printing the contents of an sql table in MySQL. Categories : MySQL, PHP, HTML and PHP, Databases | | | PHP template processing Categories : PHP, Templates, HTML and PHP | | | XDT Topsite (Gold v1.0) Categories : Databases, CSS, PHP, HTML and PHP, Sessions | | | function textwrap will wrap text to any desired width using <BR>\n as the default line break.
Default wrap width is 80 columns.
Categories : Strings, HTML and PHP, PHP | |
|
|
|