Populate HTML/PHP Dropdown Based on First Dropdown Selection

前端 未结 2 615
[愿得一人]
[愿得一人] 2021-01-16 08:25

I Have 1 Drop Down Which Is Used For Category (Food, Drink etc)

In my MYSQL Table (t_menu_category) I Have :

+----+---------------+------------------         


        
2条回答
  •  猫巷女王i
    2021-01-16 08:33

    you could create a PHP file with the request and call it with AJAX.

    getSubCategory.php

    getMessage();
    }
    
    $sql = 'SELECT sub_category_name as subCategory FROM t_menu_category WHERE category_name = :category';
    $stmt = $dbh->prepare($sql);
    $stmt->bindValue(':category', $category);
    $stmt->execute();
    
    return  json_encode($stmt->fetchAll());
    

    and add some jquery to catch when an category is selected and ask the server for the corresponding sub-category:

    
    

    also add a value on your first option:

    
    

提交回复
热议问题