搜索和分页sql查询php

时间:2017-05-29 17:33:58

标签: javascript php mysql pagination listjs

你好,我是php的新手,学习如何使用List.Js和php进行搜索和分页 我有问题让list.js在php中搜索并过滤查询结果。我已经在文档中遵循了这个例子,但仍然没有运气。 这是我的代码:

<div class="box-body">

<div id="listperson" align="center">
    <input type="text" placeholder="Search" class="fuzzy-search"/>
<table class="col-md-12">
    <thead>
        <tr>
            <th class="col-md-1 sort"></th>
            <th class="col-md-3 sort" data-sort="nama">Name</th>
            <th class="col-md-1 sort" data-sort="role">Role</th>
            <th class="col-md-3 sort">Email</th>
            <th class="col-sm-2 sort">No.Hp</th>
            <th class="col-sm-3 sort" data-sort="alamat">Alamat</th>
            <th class="col-sm-1 sort">Edit</th>
            <th class="col-sm-1 sort">Delete</th>
        </tr>
    </thead>
    <?php
        $peoplequery=mysqli_query($CONN,"SELECT * FROM people");
        while($people=mysqli_fetch_array($peoplequery)){
        ?>
    <tbody class="list">            
        <tr align="left">
            <td class="img">
            <img src="../img/man-128.png" class="direct-chat-img" width="10px" height="10px">
            </td>
            <td class="name"><a href="personview.php?PersonID=<?= $people['idpeople'] ?>"><?php echo $people['namadepan'] . ' ' .$people['namabelakang']; ?></a></td>
            <td class="role"><?php echo $people['role']; ?></td>
            <td class="email"><?php echo $people['email']; ?></td>
            <td class="nohp"><?php echo $people['nohp']; ?></td>
            <td class="alamat"><?php echo $people['alamat']; ?></td>                   
            <td class="edit" align="center">
            <a href="editperson.php?PersonID=<?= $people['idpeople'] ?>">
            <span class="fa-stack">
            <i class="fa fa-square fa-stack-2x"></i>
            <i class="fa fa-pencil fa-stack-1x fa-inverse"></i>
            </span>
            </a>
            </td>
            <td class="delete" align="center">
            <a href="deleteperson.php?PersonID=<?= $people['idpeople'] ?>">
            <span class="fa-stack" style="color:#ff0000; ">
            <i class="fa fa-square fa-stack-2x"></i>
            <i class="fa fa-trash fa-stack-1x fa-inverse" ></i>
            </span>
            </a>
            </td>             
        </tr>
        <?php
        $idppl = $people['idpeople'];
        }  ?>
    </tbody>
</table>
<ul class="pagination"></ul>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/list.js/1.1.1/list.min.js">
</script>
<script type="text/javascript">
var options = {
    valueNames: [ 'name', 'role', 'email'],
    page: 5,
    plugins: [
    ListPagination({})
]

};
var contactList = new List('listperson', options);
</script>

</div>

分页没有显示,搜索也不起作用。我想知道我在这里失踪了什么 任何帮助表示感谢。

1 个答案:

答案 0 :(得分:0)

您的<tbody>广告代码位于while循环中,但您的结束</tbody>代码位于该循环之外。

这可能意味着你的桌子格式不正确。这可能会让List.js感到困惑。

使用View Source...检查HTML是否正确生成总是好的。