WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : How to have a multiple-select box that stays selected after submit.
Categories : PHP, HTML and PHP Click here to Update Your Picture
Daevid Vincent
Date : Apr 12th 2000
Grade : Be the 1st to grade this Code Example
Viewed : 5420
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Daevid Vincent
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

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
Calendar using Date function
Categories : HTML and PHP, PHP, Date Time, Calendar
webcam cam view image ispy browser independant
Categories : Graphics, HTML, HTML and PHP, PHP
PageRank Display
Categories : Search Engines, HTML and PHP, PHP
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
Print out array key => value in colored HTML
Categories : PHP, Arrays, HTML and PHP
XTemplate, a template class for PHP
Categories : PHP Classes, HTML and PHP, PHP
Upload Script, Upload File Script, Input Type="File"
Categories : PHP, HTML and PHP, HTTP
The Nearly Perfect Contact Us Form
Categories : PHP, Form Processing, HTML and PHP
This script shows you the 7th latest php items from the mailing list archive on zend.com
Categories : HTML, HTML and PHP, HTTP, PHP
AITSH Statistics
Categories : Complete Programs, Databases, HTML and PHP, Sessions, PHP
Parse html (title :: meta)
Categories : PHP, HTML and PHP, Regexps
Creating thumbnails from MySQL Blobs online
Categories : PHP, MySQL, Graphics, HTML and PHP, Databases
This program will take data from a user via a web based form, validate it, show it to the user for re-validation, and finally insert it into the database. Plenty of sanity checking on the fields in the form.
Categories : MySQL, HTML and PHP, PHP, Complete Programs, Databases
Customizable encoding and decoding strings with security.
Categories : PHP, Strings, HTML and PHP