WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
Web Development Resources
Web Development Content
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
Mobile Dev World

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 : Builds JavaScript that updates the contents of one selector based on another.
Categories : HTML, Java Script, PHP, Complete Programs, General Update Picture
Leon Atkinson
Date : Jan 17th 1999
Grade : 3 of 5 (graded 10 times)
Viewed : 19717
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Leon Atkinson
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<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>



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
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
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
Bookmarklets are simple tools that extend the surf and search capabilities of Netscape and Explorer web browsers.
Categories : Java Script, HTML, General
Complete NotePad application for Websites (Like Yahoo Notepad)
Categories : PHP, Web Applications, Filesystem, Java Script, Complete Programs
Validator 98 - a PHP-script to generate form-validation-code in JavaScript.
Categories : Complete Programs, Java Script, PHP, HTML and PHP
A Complete table(ADD,EDIT,VIEW,DELETE) management System PHP,MYSQL, JAVASCRIPT
Categories : PHP, MySQL, Java Script, Databases
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
Create and restore backup of MySQL databases
Categories : MySQL, Databases, PHP, PHP Classes, 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
filesystem Show Files Script
Categories : PHP, Filesystem, Java Script
Point and Click Interface ala MS Access for creating SQL statements.
Categories : MySQL, Complete Programs, General SQL, PHP, Databases
Menu in sliding bar or tree style. Handles frames by using small amount of javascript. Handles external and internal pages. Allows custom code to replace a menu item.
Categories : PHP Classes, PHP, Java Script, DHTML
 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.