How to make cascading drop-down lists using mysql and php

后端 未结 2 1215
灰色年华
灰色年华 2020-12-12 05:31

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

2条回答
  •  一个人的身影
    2020-12-12 05:52

    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:

     ".$name.'';
                }
            } else {
                $options.="";
            }
            return($options);
        }
    ?>
    

    Then place on your main page:

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

    
                

    Repeat above for each required drop-down.

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

提交回复
热议问题