我在依赖下拉列表中遇到问题,我在这个问题上不专业
所以问题是当我选择第一个时,另一个没有从数据库获得任何值,我不知道解决方案
<?php
include 'header.php';
require 'connection.php';
?>
<div class="container">
<form id="contact" action="add_line.php" method="post">
<center> <h3>Add Line</h3></center>
<fieldset>
<?php
require 'connection.php';
$query = "select * from agents";
$result = mysqli_query($conn,$query);
?>
<div class="select">
<select class="agents-name " name="agents-name" autofocus tabindex="1">
<option selected="selected">--Select agent--</option>
<?php while ($row = mysqli_fetch_assoc($result)): ?>
<option value="<?php $row['id'];?>"><?php echo $row['name'];?></option>
<?php endwhile;?>
</select>
</div>
<div class="select" >
<select tabindex="1" name="sp_choosen" class="sp_choosen"
onChange="getState( this.value );" tabindex="2">
<option selected="selected">--Select service provider--</option>
<option value="CELLCOM">CELLCOM</option>
<option value="HoTMobile">HoTMobile</option>
<option value="Orange">Orange</option>
<option value="Pelphone">Pelphone</option>
<option value="Golan">Golan</option>
<option value="019">019</option>
</select>
</div>
<div class="select">
<select id="packet_select" name="packet_chossen" tabindex="3">
<option selected="selected">--Select packet--</option>
</select>
</div>
</fieldset>
<fieldset>
<input placeholder="customer name" type="text" tabindex="4"
name="customer_name" required >
</fieldset>
<fieldset>
<input placeholder="SIM_SERIAL" type="tel" tabindex="5" name="sim_serial"
required >
</fieldset>
<fieldset>
<input placeholder="phone_number" type="tel" tabindex="6" name="number"
required >
</fieldset>
<fieldset>
<label></label>
</fieldset>
<fieldset>
<button name="submit" type="submit" id="contact-submit" tabindex="7" >Add
Available line</button>
</fieldset>
</form>
</div>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
function getState(val) {
$.ajax({
type: "POST",
url: "dropdown_add_line.php",
data:'sp='+val,
success: function(data){
$("#packet_select").html(data);
}
});
}
</script>
<?php
include 'footer.php';
?>
这是dropdown_add_line.php:
<?php
require_once("connectione.php");
$db_handle = new DBController();
if(!empty($_POST["sp"])) {
$sp=$_POST['sp'];
$query ="SELECT * FROM packets p WHERE sp LIKE '%$sp%'";
$results = $db_handle->runQuery($query);
?>
<option value="">--Select service provider--</option>
<?php
foreach($results as $packets) {
?>
<option value= "<?php echo $packets["id"]; ?>" ><?php echo $packets["packet"]; ?></option>
<?php
}
}
?>
并且表名是&#34;数据包&#34;列是&#34; id&#34;,&#34; sp&#34;,&#34; packet&#34;