php - How to only shown one table after clicking search button? -
i have 2 tables when search member name. link :
i wanted search result shown after search.
my code:
<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 * member member_name '$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 * 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>
please include php file me too!
to in easiest way try use code:
<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 * member member_name '$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 * 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>
but recommend use sql union operator.
it make life easy these type of problems
Comments
Post a Comment