Location: PHPKode > scripts > Cascade Drop Down > cascade-drop-down/docs/Manual.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Manual ----- Dynamic Drop Down, Loads Value With out refreshing Page (Data from Database) </title>
<style type="text/css">
<!--
.style4 {
	font-size: 12px;
	font-family: Tahoma;
}
.style5 {font-size: 12px; font-family: Tahoma; font-weight: bold; }
-->
</style>
</head>

<body>
<p class="style4"><strong> Country &ndash; State Drop Down &ndash; (Using Database) &lt;gobinathm at gmail dot com&gt; </strong><strong>&nbsp;</strong></p>
<p class="style4"> The Basic requirement for me to write a class of this kind is to avoid the page refreshing when it has two drop downs which is depend on another (like parent and child).When the page needs to be reloaded it is not pleasant for the users to wait until the page reload is complete, especially when their Internet to the server is slow.</p>
<p class="style4">So what this class does is to generate Javascript code dynamically by fetching the select input option values from a database table and switch them when the user changes the parent select input.The class has two basic functions where one is responsible for querying the database and other is responsible for generating the Javascript code.<span class="style4">There is also a function which is responsible for generating the HTML code for the select input.</span><br />
  <br />
  <span class="style4">Here is the Example create by implementing the class.. </span></p>
<ol class="style4">
  <li> &lt;?php </li>
  <li> // Script That is used to create Object and Perform the Function Call </li>
  <li> &nbsp;</li>
  <li> /* database configuration */ </li>
  <li> // Please use your database configurations </li>
  <li> $dbConfig['type']=&quot;mysql&quot;; </li>
  <li> $dbConfig['server']=&quot;localhost&quot;; </li>
  <li> $dbConfig['username']=&quot;root&quot;; </li>
  <li> $dbConfig['password']=&quot;root&quot;; </li>
  <li> $dbConfig['database']=&quot;phpclasses&quot;; </li>
  <li></li>
  <li> // Include the class </li>
  <li> include_once(&quot;JSDropDown.class.php&quot;); </li>
  <li></li>
  <li> //Declare the Form Name </li>
  <li> $frmObjName=&quot;JSddForm&quot;; </li>
  <li> echo &quot;&lt;form name=\&quot;$frmObjName\&quot; method=\&quot;post\&quot;&gt;&quot;; </li>
  <li> &nbsp;</li>
  <li> $JSdd = new JSDropDown($dbConfig); </li>
  <li> $JSdd-&gt;DataFetch(); // Call the Function which will fetch the data. </li>
  <li> $JSdd-&gt;createfrmObject($frmObjName); // Pass the Current Form name as the parameter </li>
  <li> &nbsp;</li>
  <li> $JSdd-&gt;close_JSDropDown_database(); </li>
  <li> echo &quot;&lt;/form&gt;&quot;; </li>
  <li> ?&gt; </li>
</ol>

 <strong> <span class="style4">Line 6-10</span></strong><span class="style4">: Contains the Database Information 
 <strong><br />
 Line 13 :</strong> Includes the JSDropDown class to this script 
 <strong><br />
 Line 16 :</strong> Declare the Form Name 
 <strong><br />
 Line 17 &amp; 24 :</strong> Will create the form Opening Tag &amp; Closing Tag respectively <strong><br />
 Line 19 :</strong> Call to the Constructor which will establish the connection to the Database 
 <strong><br />
 Line 20 :</strong> Call the Function Which Fetchs the Data and Store it in an Array 
 <strong><br />
 Line 21 :</strong> This Create the From Object; 
 <strong><br />
 Line 23 :</strong> Close the Database Connection 
 </p>

 </span>
<p class="style4"> You can use the<strong> Mysql Schema</strong> to Create the Data Structure </p>

<p class="style5"> For City Master Table; // Other Wise Country </p>

<p class="style4"> CREATE TABLE `citymaster` ( 
  <br />
  `city_id` int(11) NOT NULL auto_increment, 
  <br />
  `cityname` varchar(100) default NULL,
  <br />
  PRIMARY KEY (`city_id`),<br />
  UNIQUE KEY `city_id` (`city_id`)
  )<br /> 
  TYPE=MyISAM AUTO_INCREMENT=1 ; </p>
<p class="style4"><strong>For Region Master // Other Wise State</strong></p>
<p class="style4"> CREATE TABLE `region` ( <br />
`rid` int(11) NOT NULL auto_increment, <br />
`city_id` int(11) NOT NULL default '0', <br />
`region_name` varchar(250) NOT NULL default '', <br />
PRIMARY KEY (`rid`) ) <br />
TYPE=MyISAM AUTO_INCREMENT=1 ; </p>
<p class="style4">Active Example: <a href="http://www.gobinath.com/sandbox/Cascade_Drop_Down/" target="_blank">http://www.gobinath.com/sandbox/Cascade_Drop_Down/</a></p>
<p class="style4">&nbsp; </p>
</body>
</html>
Return current item: Cascade Drop Down