当我搜索会员名称时,我有2个这样的表。 链接:
我希望搜索结果仅在搜索后显示。
我的代码:
<div id = "subtitle">
View Members
</div>
<div id = "searchbox">
<form method="post">
<center><input type="text" maxlength="100" required placeholder="Enter Full Name" name ="search" autocomplete="off" value="">
<input type="submit" name="btn" value="SEARCH NOW!"></p></center>
</form>
</div>
<?php
if(isset($_POST["btn"]))
{
$search = $_POST["search"];
$sql = "select * from member where Member_Name like '$search%' ";
$result = mysqli_query($conn,$sql);
$rowcount = mysqli_num_rows($result);
if($rowcount==0)
echo "Sorry ,no records found!";
else
{
?>
<center><table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>Member ID</th>
<th>Member Name</th>
<th>Actions</th>
</tr>
<?php
while($row=mysqli_fetch_assoc($result)) //display
{
?> <tr>
<td></td>
<td><?php echo $row["Member_ID"]?></td>
<td><?php echo $row["Member_Name"]?></td>
<td><a href=Admin_MemberDetails.php?id=".$row["Member_ID"]."><img src=../Images/ViewFile.png height=37px title=View></a>
<a href=Admin_EditMember.php?id=".$row["Member_ID"]."><img src=../Images/edit.png height=37px title=Edit></a>
</td>
</tr>
</table>
</center>
<?php
}
}
}
?>
<center><table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>Member ID</th>
<th>Member Name</th>
<th>Actions</th>
</tr>
<?php
$sql = "select * from legoclub_guesthouse.member";
$result = mysqli_query($conn,$sql);
$rowcount= mysqli_num_rows($result);
while($row=mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td></td>";
echo "<td>$row[Member_ID]</td>";
echo "<td>$row[Member_Name]</td>";
echo "<td><a href=Admin_MemberDetails.php?id=".$row["Member_ID"]."><img src=../Images/ViewFile.png height=37px title=View></a>
<a href=Admin_EditMember.php?id=".$row["Member_ID"]."><img src=../Images/edit.png height=37px title=Edit></a>
</td>";
echo "</tr>";
}
?>
</table><center>
</div>
请为我包含php文件!
答案 0 :(得分:0)
要以最简单的方式执行此操作,请尝试使用此代码:
<div id = "subtitle">
View Members
</div>
<div id = "searchbox">
<form method="post">
<center><input type="text" maxlength="100" required placeholder="Enter Full Name" name ="search" autocomplete="off" value="">
<input type="submit" name="btn" value="SEARCH NOW!"></p></center>
</form>
</div>
<?php
if(isset($_POST["btn"]))
{
$search = $_POST["search"];
$sql = "select * from member where Member_Name like '$search%' ";
$result = mysqli_query($conn,$sql);
$rowcount = mysqli_num_rows($result);
if($rowcount==0)
echo "Sorry ,no records found!";
else
{
?>
<center><table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>Member ID</th>
<th>Member Name</th>
<th>Actions</th>
</tr>
<?php
while($row=mysqli_fetch_assoc($result)) //display
{
?> <tr>
<td></td>
<td><?php echo $row["Member_ID"]?></td>
<td><?php echo $row["Member_Name"]?></td>
<td><a href=Admin_MemberDetails.php?id=".$row["Member_ID"]."><img src=../Images/ViewFile.png height=37px title=View></a>
<a href=Admin_EditMember.php?id=".$row["Member_ID"]."><img src=../Images/edit.png height=37px title=Edit></a>
</td>
</tr>
<?php
}
$sql = "select * from legoclub_guesthouse.member";
$result = mysqli_query($conn,$sql);
$rowcount= mysqli_num_rows($result);
while($row=mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td></td>";
echo "<td>$row[Member_ID]</td>";
echo "<td>$row[Member_Name]</td>";
echo "<td><a href=Admin_MemberDetails.php?id=".$row["Member_ID"]."><img src=../Images/ViewFile.png height=37px title=View></a>
<a href=Admin_EditMember.php?id=".$row["Member_ID"]."><img src=../Images/edit.png height=37px title=Edit></a>
</td>";
echo "</tr>";
}
?>
</table>
</center>
<?php
}
}
?>
</div>
但我建议您使用SQL UNION Operator.
这将使您的生活轻松解决这些类型的问题