Thanks Elias,

I took a look at the code and there are indeed many things to learn;
however, it's all in js.
I'm trying to have php write the js, but I don't know enough about arrays
and manipulating their elements.


-----Original Message-----
From: lallous [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 11, 2002 2:02 AM
Subject: [PHP] Re: Dependent Dropdown Boxes


Try to learn many things from the test code i created below:

Good luck,


"Roger Lewis" <[EMAIL PROTECTED]> wrote in message
> The Situation:
> I'm trying to create a pair of dynamic dropdown boxes where the options in
> the second box are dependent on the selection in the first box.  I call
> first box "categories" and the second, "subcategories".  I want to store
> categories and subcategories in a mysql table(s) so that a user can
> dynamically update them.  Currently, I have a single table called
> categories, with columns: id, category, and subcategory.
> The primary code for selecting the options for the second box is in
> javascript.  This code makes use of the following datasets for storing the
> various categories and subcategories.  If I can get php to generate this
> text, then the dependent boxes will work.
> datasets=new Array();
> ory1_4".split(",");
> ,");
> datasets[2]="Category3,subCategory3_1, subCategory3_2,
> subCategory3_3,subCategory3_4,subCategory3_5".split(",");
> ory4_4".split(",");
> ory5_4,subCategory5_5,subCategory5_6".split(",");
> etc.
> The Problem:
> Using the following code I can get php to print the results, but only in a
> line-by-line, category/subcategory format.  Of course, this is NOT what is
> needed.  Each subcategory name should be on the same line as its
> category.
> <?php
> $dbConnect = mysql_connect("localhost", "root", "pwd");
> mysql_select_db("new_kb",$dbConnect);
> $sql = "SELECT * from categories";
> $result = mysql_query($sql);
> for ($count = 1; $row = mysql_fetch_row ($result); ++$count)
> {
> print "<br>datasets[$count]=\"";
> print "$row[1],";
> print "$row[2]\"";
> }
> ?>
> datasets[0]="Category1,subCategory1_1
> datasets[1]="Category1,subCategory1_2
> datasets[2]="Category1,subCategory1_3
> datasets[3]="Category1,subCategory1_4
> datasets[4]="Category2,subCategory2_1
> datasets[5]="Category2,subCategory2_2
> etc.
> Can someone explain how to write the php code to output the category and
> subcategory names from the mysql table to match the javascript format
> Thanks in advance for any help or suggestions.
> Roger Lewis

PHP General Mailing List (
To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to