下面代码的思路是用户将根据维护操作编号、操作类型、执行操作的成员或PC需要维护的员工进行搜索。例如,当用户选择操作类型时,将显示一个下拉菜单,然后他选择类型。之后,将显示维护信息表。例如,用户选择打印类型。该表将显示以下信息:
操作编号、成员姓名、员工姓名、维护类型
1001,阿德姆,约翰,印刷 1003,乔治,史密斯,印刷 1010,威廉,约翰,印刷
我面临的问题是,例如,当用户通过操作编号选择搜索时,他选择操作编号为 1001,其余行(基于先前搜索显示的 1003 和 1010)仍然显示(它们必须被隐藏,因为它们与搜索类型不匹配)。
代码是
<script>
function check() {
var dropdown = document.getElementById("OpType");
var current_value = dropdown.options[dropdown.selectedIndex].value;
if (current_value == "OpNo") {
document.getElementById("operationno").style.display = "block";
document.getElementById("MainType").style.display = "none";
document.getElementById("MemName").style.display = "none";
document.getElementById("EmpName").style.display = "none";
}
else if (current_value == "OpTyp") {
document.getElementById("MainType").style.display = "block";
document.getElementById("MemName").style.display = "none";
document.getElementById("EmpName").style.display = "none";
document.getElementById("operationno").style.display = "none";
}
else if (current_value == "OpMem") {
document.getElementById("MemName").style.display = "block";
document.getElementById("operationno").style.display = "none";
document.getElementById("MainType").style.display = "none";
document.getElementById("EmpName").style.display = "none";
}
else if (current_value == "OpEmp"){
document.getElementById("MemName").style.display = "none";
document.getElementById("operationno").style.display = "none";
document.getElementById("MainType").style.display = "none";
document.getElementById("EmpName").style.display = "block";
}
else if (current_value == "blank") {
document.getElementById("MainType").style.display = "none";
document.getElementById("MemName").style.display = "none";
document.getElementById("EmpName").style.display = "none";
document.getElementById("operationno").style.display = "none";
}
}
</script>
<form name="f1" action="FollowOperations.php" method="post">
<select id="OpType" onChange="check();">
<option value="blank">Choose</option>
<option value="OpNo">Operation No</option>
<option value="OpTyp">Operation Type</option>
<option value="OpMem">Maintenance Member</option>
<option value="OpEmp">Employee</option>
</select><br>
<input class="tb10" type="text" id="operationno" size="4" style="text-align: center" style="display: none">
<select id="MainType" style="display: none">
<option value="blank">Choose</option>
<option value="printing">Printing</option>
<option value="maintenance">PC Maintenance</option>
<option value="internet">Internet Problem</option>
<option value="software">Software</option>
<option value="email">Email Problem</option>
<option value="usbcd">USB/CD Problem</option>
</select>
<select id="MemName" style="display: none">
<option value="blank">Choose</option>
<option value="john">John</option>
<option value="hen">Hen</option>
</select>
<select id="EmpName" style="display: none">
<option value="blank">Choose</option>
<option value="smith">Smith</option>
<option value="will">William</option>
<option value="Gor">George</option>
</select>
<input type="submit" value="Submit" class="button" />
</form>
<?php
if (isset($_POST['formsubmitted']))
{
$operationno = $_POST['ono'];
echo "<table id='tfhover' class='tftable' border='1' align='center'>";
echo "<tr align='center'><th></th><th align='center'>Type</th><th>Employee</th><th align='center'>Member</th><th align='center'>Operation No</th></tr>";
$query_retrieve_maintenance = "Select * from Maintenance where ID = '$operationno'";
$result_retrieve_maintenance = mysqli_query($dbh, $query_retrieve_maintenance);
while($row1 = mysqli_fetch_array($result_retrieve_maintenance))
{
echo "<tr>";
echo "<td><a href='PastOperationsDet.php?operation_number=".$row1['ID']."' target='_blank'>Show</a></td> ";
echo "<td>".$row1['Type']."</td> ";
echo "<td>".$row1['MemName']."</td> ";
echo "<td>".$row1['EmpName']."</td> ";
echo "<td>".$row1['ID']."</td> ";
}
$MainType = $_POST['mt'];
$query_retrieve_by_type = "Select * from Maintenance where Type = '$MainType'";
$result_retrieve_by_type = mysqli_query($dbh, $query_retrieve_by_type);
while($row1 = mysqli_fetch_array($result_retrieve_by_type))
{
echo "<tr>";
echo "<td><a href='PastOperationsDet.php?operation_number=".$row1['ID']."' target='_blank'>Show</a></td> ";
echo "<td>".$row1['Type']."</td> ";
echo "<td>".$row1['MemName']."</td> ";
echo "<td>".$row1['EmpName']."</td> ";
echo "<td>".$row1['ID']."</td> ";
}
$MemName = $_POST['mn'];
$query_retrieve_by_member = "Select ID from Member where Name = '$MemName'";
$result_retrieve_by_member = mysqli_query($dbh, $query_retrieve_by_member);
$membID = mysqli_fetch_row($result_retrieve_by_member);
$memb_id = $membID[0];
$query_retrieve_by_membername = "Select * from Maintenance where MemberID = '$memb_id'";
$result_retrieve_by_membername = mysqli_query($dbh, $query_retrieve_by_membername);
while($row1 = mysqli_fetch_array($result_retrieve_by_membername))
{
echo "<tr>";
echo "<td><a href='PastOperationsDet.php?operation_number=".$row1['ID']."' target='_blank'>Show</a></td> ";
echo "<td>".$row1['Type']."</td> ";
echo "<td>".$memb_id."</td> ";
echo "<td>".$row1['EmpName']."</td> ";
echo "<td>".$row1['ID']."</td> ";
}
$EmpName = $_POST['me'];
$query_retrieve_by_employee = "Select ID from Employee where Name = '$EmpName'";
$result_retrieve_by_employee = mysqli_query($dbh, $query_retrieve_by_employee);
$emplID = mysqli_fetch_row($result_retrieve_by_employee);
$empl_id = $emplID[0];
$query_retrieve_by_emplid = "Select * from Maintenance where EmployeeID = '$empl_id'";
$result_retrieve_by_emplid = mysqli_query($dbh, $query_retrieve_by_emplid);
while($row1 = mysqli_fetch_array($result_retrieve_by_emplid))
{
echo "<tr>";
echo "<td><a href='PastOperationsDet.php?operation_number=".$row1['ID']."' target='_blank'>Show</a></td> ";
echo "<td>".$row1['Type']."</td> ";
echo "<td>".$row1['MemName']."</td> ";
echo "<td>".$empl_id."</td> ";
echo "<td>".$row1['ID']."</td> ";
}
echo "</table>";
}
?>