我有1个选择下拉列表,我想根据选择下拉列表#1的值创建另一个选择下拉列表。例如,我的下拉列表#1的值为13-001,13-002,13-003,当我在13-001中选择时,它会在数据库中显示表中的记录,并且有一列po_number。我想要另一个选择下拉列表,其值为po_number取决于下拉列表#1的值。
就像这样。下拉列表#1 13,-001,13-002,13-003
下拉#2当我选择13-001时,下拉列表#2的值是111,222,333,基于从po_number列获取的值,并且仅显示下拉列表#1 13-001和下拉列表#2 111的记录。我只是在我的脚本中添加了一些id,但我不知道下一步是什么。
bid.php
<script>
function showUser(str,ids) {
var $txtHint = $('#txtHint');
if (str=="" || ids=="") {
$txtHint.html('');
return;
}
$txtHint.load('bid_list.php?q='+str+'&id='+ids)
}
</script>
</head>
<body onload=showUser(str="ALL")>
<?php
$mysqli = new mysqli("localhost", "root", "", "app");
$result = $mysqli->query("SELECT bid FROM procurement WHERE bid LIKE '13-___' OR bid LIKE '1_-___' OR bid LIKE '2_-___' GROUP BY bid ORDER BY bid");
$option = '';
while($row = $result->fetch_assoc())
{
$option .= '<option value = "'.$row['bid'].'">'.$row['bid'].'</option>';
}
?>
<div style="text-align:center;">
<select name="users" onchange="showUser(this.value)" style="overflow:scroll;width:100px;">
<option value="ALL" selected='ALL'>ALL</option>
<?php echo $option; ?>
</select>
<?php
$mysqli = new mysqli("localhost", "root", "", "app");
$result = $mysqli->query("SELECT po_number FROM procurement WHERE po_number GROUP BY po_number ORDER BY po_number");
$option1 = '';
while($row = $result->fetch_assoc())
{
$option1 .= '<option value = "'.$row['po_number'].'">'.$row['po_number'].'</option>';
}
?>
<select style="overflow:scroll;width:100px;">
<option value="ALL" selected='ALL'>ALL</option>
<?php echo $option1; ?>
</select>
<div id="txtHint"></div>
bid_list.php
<?php
$mysqli = new mysqli("localhost", "root", "", "app");
$q = $_GET["q"];
$where = '';
if ( $q != 'ALL' ) {
$where = " WHERE bid='$q' ";
}
$result1 = $mysqli->query("
SELECT bid, item_name, item_description, unit, unit_cost, quantity, supplier, po_number, po_date, counter, SUM(unit_cost*quantity) AS total_amount
FROM procurement
$where
GROUP BY counter ORDER BY bid
");
echo'<table id="tfhover" cellspacing="0" class="tablesorter" style="text-transform:uppercase;">
<thead>
<tr>
<th colspan="3" id="none" style="cursor: default;"></th>
<th title="Item Name">Item Name</th>
<th title="Item Description">Description</th>
<th title="Example : Pc, Pcs, Box and Etc.">Unit</th>
<th title="Item Price">Unit Cost</th>
<th title="Total Item Quantity">QTY</th>
<th title="Total Price">Total Amount</th>
<th title="Name of Supplier">Supplier</th>
<th title="Purchase Order #">PO #</th>
<th title="Purchase Order Date">PO Date</th>
</tr>
</thead>';
echo'<tbody>';
while($row = $result1->fetch_assoc()){
if($row['bid'] != '')
{
echo'<tr>
<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?de='.$row["counter"].'" onclick="return confirm(\'Really want to delete ?\');"><img src="images/del.png" border="0" width="10" height="10" title="Delete"></a></td>
<td align="center"><a class="fancybox" href="edit.php?pn='.$row["counter"].'"><img src="images/edit.png" border="0" width="10" height="10" title="Edit"></a></td>
<td align="center"><a class="fancybox" href="comments.php?pn='.$row["counter"].'"><img src="images/remarks.png" border="0" width="10" height="10" title="Remarks and Notes"></a></td>
<td>'.$row['item_name'].'</td>
<td>'.$row['item_description'].'</td>
<td>'.$row['unit'].'</td>
<td>'.number_format($row['unit_cost'], 2, '.', ',').'</td>
<td>'.$row['quantity'].'</td>
<td>'.number_format($row['total_amount'], 2, '.', ',').'</td>
<td>'.$row['supplier'].'</td>
<td>'.$row['po_number'].'</td>
<td>'.$row['po_date'].'</td>
</tr></tbody>';
}
}
echo "</table>";
if (!$mysqli) {
die('Connect Error: ' . mysqli_connect_error());
}
mysqli_close($mysqli);
?>