Location: PHPKode > scripts > Cascade Select Associative > cascade-select-associative/csa_doc.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <meta content="text/html; charset=ISO-8859-1"
  <title>cascadeSelectAssoc Class Example</title>
<b>How to use the CascadeSelectAssoc Class</b><br>
This short manual is written to explain how to use the
CascadeSelectAssoc Class.
<br>This class is derived from the CascadeSelect Class written by Vedanta Barooah.<br>
As we can see in the next code example:
1  &lt;?php include("cascadeSelectAssoc.php"); 
2  $motherArray = array('1'=&gt;'Food','2'=&gt;'Drinks', '3'=&gt;'Fruits', '4'=&gt;'Veg');
3  $childArray = array(
4       "1"  =&gt; array(
5           "1"  =&gt; "Ham",
6           "2" =&gt; "Burger",
7           "3" =&gt; "Pizza",
8           "4" =&gt; "Burrito"
9       ),
10      "2"  =&gt; array(
11          "1"  =&gt; "Beer",
12          "2"  =&gt; "Soda",
13          "3"  =&gt; "Coke",
14          "2"  =&gt; "Tequila"
15     ),
16      "3"  =&gt; array(
17          "1"  =&gt; "Banana",
18          "2"  =&gt; "Apple",
19          "3"  =&gt; "Mango",
20          "4"  =&gt; "Pineapple"
21     ),
22      "4"  =&gt; array(
23          "1"  =&gt; "Tapioca",
24          "2"  =&gt; "Cabbage",
25          "3"  =&gt; "Brocoli",
26		    "4"  =&gt; "Onion",
27		    "5"  =&gt; "Potato"
28  	)
29  );
31  $o=new cascadeSelectAssoc("testForm");
32  $o-&gt;setName("select1","select2");
33  $o-&gt;setHeight(1,1);
34  $o-&gt;setData($motherArray,$childArray);
35  $o-&gt;writeScript();
36  ?&gt;
37  &lt;form name="testForm" method="post"&gt;
38  &lt;?php 
39  $o-&gt;drawMother();
40  $o-&gt;drawChild();
41  ?&gt;
42  &lt;br&gt;
43  &lt;input type="submit" value="GO"&gt;
44  &lt;/form&gt;
45  &lt;/body&gt;
46  &lt;/html&gt;

On line 1 we include the file with our class. Then from line 2 to 22 we initialize and populate the arrays with our data. Look that the arrays are tied by mean of a common key; this key relates an entry on the mother array with an array in the child array, just as we do it when we link two tables in a one to many relationship.
In line 31 we initializs the class, and the constructor takes the form name as the argument. In line 13 we set the names of the select boxes as select1 and select2 respectively, and set the size of the selects boxes respectively, takes two integer arguments or sets to default 5.
In line 34 we set the data for each one of the select boxes and then we generate the JavaScript code that make the magic, in line 35. Finally, in lines 39-40 we draw the first and the second select boxes.
<b>Getting tha data from a RDBMS</b>
Usually you don't have to hand code the mother and child arrays, you get them from a relational database like PostgreSQL.
You can find a database example in the file <var>csa_db_example</var>, that relies on some function using PostgreSQL and PEAR's DB.php.
The file <var>csa_test_data.sql</var> is an SQL script that creates and populate a test database. This script works fine with PostgreSQL, but should work with MySQL or other databases, with minor changes.

Roberto Andrade Fonseca &lt;hide@address.com&gt;
Return current item: Cascade Select Associative