我创建了一个包含3个标签的表单。每个选项卡都有不同的下拉菜单和一个按钮。我想从下拉菜单中选择一个值,并在按下搜索按钮时显示数据库的结果。每个选项卡应基于所选值显示不同的表。但是问题是当我为一个选项卡显示一个表时,默认情况下每个选项卡都会显示该表。我想将表格显示在选项卡式搜索框的边界之外,并且每个选项卡都应显示不同的表格。 我怎样才能做到这一点?这是我用于标签式搜索框的代码:
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active " id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Number</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Name</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">Results</a>
</li>
</ul>
标签内搜索框的代码:
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab"><h4>Select Number</h4>
<form id="stnumber" action="" method="post" enctype="multipart/form-data" >
<select id="stnumber" name="stnumber">
<option>Select an option</option>
<?php
$sql="SELECT DISTINCT numbers FROM table ";
$result = mysql_query($sql,$conn);
while ($row = mysql_fetch_array($result)) {
echo "<option class='stnumber' value=' " . $row['stnumber'] ."'>" . $row['stnumber'] ."</option>";
}
?>
</select>
<input type="submit" name="submit" value="Search" />
//same for the other two tabs but with different records
这是我要根据搜索结果显示的表的代码
<?php
$count=1;
$header_printed=false;
$con=mysqli_connect("localhost","root","","table");
$stnumber=isset($_POST['stnumber']) ? trim($_POST['stnumber']): '';
$sql="SELECT * FROM table WHERE stnumber= '".$stnumber."' ";
$result = mysqli_query($con,$sql);
if($result){
while (($row=mysqli_fetch_assoc($result)) ){
if($header_printed==false){
echo "<table border='1' cellpadding='10' style='display: block;'>";
echo "<tr> <th>Number</th></tr>";
$header_printed = true;
}?>
<tr>
<td align="center"><?php echo $row["stnumber"]; ?></td>
</tr>
<?php $count++; }}
else{echo "No order Found";}?>
</table>
//same for the other two tabs but with different records