Two Dependent Dropdown In PHP – How to make dependent dropdown list using jquery Ajax?

two dependent dropdown in php – Dependent Drop-down List in PHP using jQuery AJAX with Category SubCategory Example

Two Dependent Dropdown In PHP

1.itsolutionstuck_category
2.itsolutionstuck_subcategory

Step 1: Create Tables and Dummy Data

itsolutionstuck_category table:
[php]
CREATE TABLE `itsolutionstuck_category` (
`id` int(11) NOT NULL,
`name` varchar(155) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT ‘0000-00-00 00:00:00’
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
[/php]

itsolutionstuck_subcategory table:
[php]
CREATE TABLE `itsolutionstuck_subcategory` (

`id` int(11) NOT NULL,
`category_id` int(12) NOT NULL,
`name` varchar(155) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT ‘0000-00-00 00:00:00’

) ENGINE=InnoDB DEFAULT CHARSET=latin1;
[/php]

Step 2: Create index.php file

index.php
[php]



PHP – How to make dependent dropdown list using jquery Ajax? – itsolutionstuck.com


Select Category and get bellow Related Sub Category




[/php]

Step 3: Add DB Configuration File

db_config.php
[php]

[/php]

Step 4: Add Ajax File

ajaxpro.php
[php]
query($sql);

$json = [];
while($row = $result->fetch_assoc()){
$json[$row[‘id’]] = $row[‘name’];
}

echo json_encode($json);
?>
[/php]

See also :  Add/remove multiple input fields dynamically with Jquery Laravel 5.8 Example

Leave a Comment