How to search an HTML table that collects data fro

2019-09-22 06:56发布

trying to do a search on an html table want to be able to type the users nickname and it gives me all the users details on the same table.

                        <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
                            <thead>
                                <tr>
                                    <th>Nickname</th>
                                    <th>State</th>
                                    <th>city</th>
                                    <th>address</th>
                                </tr>
                            </thead>
                            <tbody>
                               <?php
            $sql = "SELECT * FROM houses"; 
            $q=$conn->query($sql);
           while ($row = mysqli_fetch_array($q)) {
 ?>
              <tr>
            <td><?php echo $row['nickname']; ?></td>
            <td><?php echo $row['state']; ?></td>
            <td><?php echo $row['city']; ?></td>
            <td><?php echo $row['address']; ?></td>
        </tr>
<?php
           }

        ?>
                            </tbody>
                        </table>

标签: php mysqli
1条回答
仙女界的扛把子
2楼-- · 2019-09-22 07:37

You need to use WHERE in your SQL query:

$sql = "SELECT * FROM houses WHERE nickname = '{$nickname}'";

you also need to use an isset in order to have the word from your HTML input.

查看更多
登录 后发表回答