36 lines
911 B
PHP
36 lines
911 B
PHP
<h2>Dependent Dropdown in php MySQL</h2>
|
|
<?php
|
|
require_once('db.php');
|
|
$member_result = $conn->query('select * from members');
|
|
?><select name="member" id="members-list">
|
|
<option value="">Select Member</option>
|
|
<?php
|
|
if ($member_result->num_rows > 0) {
|
|
// output data of each row
|
|
while($row = $member_result->fetch_assoc()) {
|
|
?>
|
|
<option value="<?php echo $row["id"]; ?>"><?php echo $row["member_name"]; ?></option>
|
|
<?php
|
|
}
|
|
}
|
|
?>
|
|
</select>
|
|
</br></br></br>
|
|
<select name="product" id="products-list">
|
|
<option value=''>Select Product</option>
|
|
</select>
|
|
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
|
|
<script>
|
|
$('#members-list').on('change', function(){
|
|
var member_id = this.value;
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "get_products.php",
|
|
data:'member_id='+member_id,
|
|
success: function(result){
|
|
$("#products-list").html(result);
|
|
}
|
|
});
|
|
});
|
|
</script>
|