<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 */
/***************************************************************/
/* 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];
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";
<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>