|
|
|
<HTML>
<HEAD>
</HEAD>
<BODY>
<?
/***************************************************************/
/*Code: PHP3 */
/*Author: Leon Atkinson <leon@clearink.com> */
/*Creates two form fields based on data from a database */
/*Writes javascript that update field 2 based on field 1 */
/***************************************************************/
/* To simulate database connectivity, I'll fill some arrays */
$store_id = array( "1", "3", "4", "5", "6");
$store_state = array( "California", "California", "California", "Nevada", "Utah");
$store_city = array( "Los Angeles", "San Francisco", "Walnut Creek", "Las Vegas", "Salt Lake City");
$numStores = 5;
$distinct_states = array( "California", "Nevada", "Utah");
/* create the javascript function the updates the city list */
echo "<SCRIPT Language=\"JavaScript\">\n";
echo "function UpdateCity()\n";
echo "{\n";
/* clear the city selector */
echo "\tvar City = document.choose_store.city.options.length;\n";
echo "\twhile(City > 0)\n";
echo "\t{\n";
echo "\t\tCity--;\n";
echo "\t\tdocument.choose_store.city.options[City].text = '';\n";
echo "\t\tdocument.choose_store.city.options[City].value = '';\n";
echo "\t}\n\n";
echo "\tdocument.choose_store.city.options[0].selected = true;\n\n";
/* figure out which state is selected*/
echo "\tvar StateSelected = 0;\n";
echo "\twhile(document.choose_store.state.options[StateSelected].selected==false) StateSelected++;\n\n";
$StoreState = "";
$CityCount = 0;
/* If this weren't a demo, I'd run a query something like: */
/* select * from store order by State */
/* But since this is a demo, I'll just read from an array */
$RowCount = 0;
while($RowCount < $numStores)
{
$store_ID = $store_id[$RowCount];
$store_State = $store_state[$RowCount];
$store_City = $store_city[$RowCount];
if($StoreState != $store_State)
{
if($StoreState != "")
{
echo "\t}\n";
}
echo "\tif(document.choose_store.state.options[StateSelected].value == '$store_State')\n";
echo "\t{\n";
echo "\t\tdocument.choose_store.city.options[0].value = 0;\n";
echo "\t\tdocument.choose_store.city.options[0].text = 'Choose a Store Location';\n\n";
$StoreState = $store_State;
$CityCount=1;
}
echo "\t\tdocument.choose_store.city.options[$CityCount].value = '$store_ID';\n";
echo "\t\tdocument.choose_store.city.options[$CityCount].text = '$store_City';\n\n";
$CityCount++;
$RowCount++;
}
echo "\t}\n";
echo "}\n";
echo "</SCRIPT>\n\n";
echo "<CENTER><FORM NAME=choose_store>";
echo "<SELECT NAME=state onChange=\"UpdateCity();\">\n";
/* This is another place I'd put a query: */
/* select distinct State from store order by State */
echo "<OPTION VALUE=0>Choose a State";
$RowCount = 0;
while($RowCount < count($distinct_states))
{
echo "<OPTION VALUE=\"";
echo $distinct_states[$RowCount];
echo "\">";
echo $distinct_states[$RowCount];
echo "\n";
$RowCount++;
}
echo "</SELECT>\n";
/* Now we need to know how many cities are listed for the state with the most stores */
/* select count(*) as items from store group by State order by items desc */
$MaxItems = 3;
echo "<SELECT NAME=city>\n";
$RowCount = 0;
while($RowCount <= $MaxItems)
{
echo "<OPTION VALUE=$RowCount>";
echo "Choose a Store Location\n";
$RowCount++;
}
echo "</SELECT><BR><BR>\n";
echo "</FORM></CENTER>";
echo "<SCRIPT Language=\"JavaScript\">UpdateCity();</SCRIPT>\n";
?>
<BR>
<BR>
<CENTER>
Check out
<A HREF="http://www.restorationhardware.com/secondary.htmy?id=location">www.RestorationHardware.com</A>
to see this code used to take to a real database.
</CENTER>
</BODY>
</HTML> |
|
| Parses HTTP_USER_AGENT so that you can customize your site to different browsers Categories : HTML, PHP, Complete Programs | | | This is a script that list all image files on a given directory, and displays
the thumbnails nicely formated within an HTML table. It also make use of
JavScript to open pop up windows when the users want to see the full photo. Categories : Graphics, PHP, Complete Programs, Java Script | | | Snipe.Net's Web Design Color Scheme Previewer- Allows uses to input hex
codes for their text, background, and link colors, and preview the color
scheme with their background image. Example:
http://www.snipe.net/tech/snipeschool/hex.php3 Categories : PHP, HTML and PHP, General, Graphics, HTML | | | Bookmarklets are simple tools that extend the surf and
search capabilities of Netscape and Explorer web browsers. Categories : Java Script, HTML, General | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | Validator 98 - a PHP-script to generate form-validation-code in JavaScript. Categories : Complete Programs, Java Script, PHP, HTML and PHP | | | Complete NotePad application for Websites (Like Yahoo Notepad) Categories : PHP, Web Applications, Filesystem, Java Script, Complete Programs | | | Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs. Categories : Databases, PHP, MySQL, Complete Programs | | | A simple class with some HTML output functions that would come in handy for consistent page layout etc. Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation | | | PHP-MySQL shopping cart
Categories : PHP, Ecommerce, Complete Programs | | | Point and Click Interface ala MS Access for creating SQL statements. Categories : MySQL, Complete Programs, General SQL, PHP, Databases | | | Searches through a local INN server's discussions Categories : Search, Complete Programs, PHP | | | phpCards - PHP/mySQL postcard script with web based admin to add, edit, and delete cards and categories. Very easy to install. Categories : PHP, Complete Programs, HTML and PHP, MySQL | | | Expose - PHP template engine, supports server and client-sided caching,a plugin system, multiple languages, template script language is based on PHP itself. Categories : PHP, PHP Classes, Templates, Complete Programs | | | PHP4 session helper HTML file.
Categories : PHP, Java Script, HTML and PHP, Sessions | |
| | | | DJ Lucs wrote :1630
Hi,
But I really what to do that selection from a database. How can I do that ? And I want a "GO" button to finish the query.
| |
|
|
|