Location: PHPKode > scripts > DropDown.inc > dropdown-inc/test_dropdown.php
<?php

include ("FormElements.inc");

print "Automatically generating drop down<BR>";
print "<FORM action=\"#\" method=\"post\"><BR>";

//the name of the drop down will be "phpclasses"
$dropdown = new DropDown("phpclasses");

//add the next couple of options manually
//note the AT_FRONT or AT_BACK, which puts it at the top or bottom of the
//list, respectively
$dropdown->addOption("-1", "Please Select", $dropdown->AT_FRONT);
$dropdown->addOption("0", "Nothing, thanks", $dropdown->AT_FRONT);
$dropdown->addOption("21", "twenty-one", $dropdown->AT_BACK);
$dropdown->addOption("20", "one less", $dropdown->AT_BACK);

//add the results from a db query.  These always get sandwiched between
//the options AT_FRONT and AT_BACK (see above)
$dropdown->addFromQuery("SELECT id, member_name FROM members");

//this outputs the drop down.  You can also just get the string 
//representing the drop down without printing by calling toString()
$dropdown->printContents();

print "<BR>";
print "<BR>";

//Another example - no db queries this time
$dropdown2 = new DropDown("anotherdropdown");
$dropdown2->addOption("3", "This is 3", $dropdown->AT_FRONT);
$dropdown2->addOption("9", "This is 9", $dropdown->AT_FRONT);
$dropdown2->addOption("69", "This is 69", $dropdown->AT_BACK);
$dropdown2->addOption("65", "This is 65", $dropdown->AT_BACK);
$dropdown2->printContents();

print "</FORM><BR>";
Return current item: DropDown.inc