Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9072325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:08:31+00:00 2026-06-16T18:08:31+00:00

I have to make a form with multiple drop-down menus that modify one another.

  • 0

I have to make a form with multiple drop-down menus that modify one another. The menus/database tables are:

Categories, Styles, Types, and Mechanisms

I have attempted to do this with my limited knowledge of Ajax, but can only seem to access MySQL once (on the initial page) to populate the Categories table without being able to then update the Styles table by querying for the next set of results. I receive an error that claims the database is empty.

I also tried having the drop-down populated through an option group to handle both the Categories and Styles with a looped query, but only the Category headings show up with all of the Style sub-values showing up blank. My code is as follows:

                $query1="SELECT categories.category_id, categories.Category_Name ";
                $query1.="FROM categories ";
                $query1.="ORDER BY categories.Category_Name ASC";
                $category_result=mysql_query($query1, $connection);

                if(!$category_result){
                    die("Database query failed: " . mysql_error());
                }

                $options="";

                $con=0;

                while ($category_row=mysql_fetch_array($category_result)) {
                    $category_name=$category_row["Category_Name"];
                    $CategoryID=$category_row["category_id"];

                    $options.="<OPTGROUP LABEL=\"$category_name\"> <br />";

                    $query2="SELECT categories.category_id, categories.Category_Name, ";
                    $query2.="styles.style_id, styles.Style_Name ";
                    $query2.="FROM categories, styles ";
                    $query2.="WHERE styles.Category_ID = $CategoryID ";
                    $style_result=mysql_query($query2, $connection);

                    if(!$style_result){
                        die("Database query failed: " . mysql_error());
                    }

                    while ($style_row=mysql_fetch_array($style_result)) {
                        $style_name=$row["Style_Name"];
                        $id=$row["style_id"];

                        $options.="<OPTION VALUE=\"$id\" <a href=\"#\" onClick=\"javascript:swapContent('$style_name');\" >".$style_name.'</OPTION>';
                    }
                    $options.='</OPTGROUP> <br />';
                }
            ?>

            <SELECT NAME="category_id">
                <OPTION VALUE=0></OPTION>
                <?php echo $options ?>choose
            </SELECT>

Any insight into what I am doing wrong would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:08:32+00:00Added an answer on June 16, 2026 at 6:08 pm

    Finally just had to figure it out on my own, but thanks for those who tried to help.

    I will post my middle table from my Class/Category/Style/Type cascading tables. First make a function such as the below:

     <?php //Category Selection
        function Category_Selection($link) {
            global $connection;
            $options="";
            if(isset($_GET["class_id"])) {
                $query="SELECT categories.category_id, categories.Category_Name ";
                $query.="FROM categories ";
                $query.="ORDER BY categories.Category_Name ASC";
                $result=mysql_query($query, $connection);
                $class_id=$_GET['class_id'];
    
                if(!$result){
                    die("Database query failed: " . mysql_error());
                }
                while ($row=mysql_fetch_array($result)) {
                    $name=$row["Category_Name"];
                    $id=$row["category_id"];
                    $link2=$link."&category_id={$id}";
                    $options.="<OPTION VALUE=\"$link2\" ";
                    if(isset($_GET["category_id"])) {
                        $category_id = $_GET['category_id'];
                        if($id==$category_id) {
                            $options.=" selected=\"selected\" ";
                        }
                    }
                    $options.=" >".$name.'</OPTION>';
                }
            } else {
                $options.="<OPTION selected=\"selected\" VALUE=0>First Select Class</OPTION>";
            }
            return($options);
        }
    ?>
    

    Then place on your main page:

    <?php session_start() ?>
        //Category
        if(isset($_GET['category_id'])) {
            $category_id=$_GET['category_id'];
            setcookie('category_id',$category_id);
            $link.="&category_id={$category_id}";
        }elseif(isset($_COOKIE['category_id'])) {
            $_GET['category_id']=$_COOKIE['category_id'];
            $category_id=$_COOKIE['category_id'];
            $link.="&category_id={$category_id}";
        }
    

    Now make your selection drop-down:

    <?php //Category Selection
                    $options=Category_Selection($link);
                ?>
                <center>
                <SELECT NAME="category_id" ONCHANGE="location = this.options[this.selectedIndex].value;">
                    <OPTION VALUE=0></OPTION>
                    <?php echo $options ?>
                </SELECT>
                </center>
    

    Repeat above for each required drop-down.

    Good luck…and, of course use MYSQLi to protect your site rather than the MYSQL shown above…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to quickly make a form that has optional menus depending on the
I need to make the program which have one form that contains PNG image
I have a drop down menu that I want to change to a multiple
i have a form with multiple select menus i want to make sure on
I have a form that has a group of 13 checkboxes that together make
I have a form on my website that does the login. To make the
I have a rails form that has a datetime input. I'd like to make
I have a form that submits values to database via Ajax and works fine
I have a form with multiple input fields that use datepicker. I have just
how to link multiple form in android eclipse?* Do i have to make multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.