首页 > 解决方案 > 使用php mysql显示数据时缺少Datatable.js搜索栏

问题描述

我正在显示来自 mysql 数据库的记录,但每次加载数据时,表都搞砸了,表头上的排序功能丢失了,顶部的搜索栏也丢失了。

我尝试将纯 HTML 文本放到每个字段中,并且可以正常工作。我真的不知道为什么它不 php 代码不起作用。

<div class="row" style="margin-top:20px;">
   <div class="col-sm-12">
        <div class="panel panel-primary">
            <div class="panel-heading">TEACHER LIST</div>
            <div class="panel-body">
            <table id="teacher-record" class="display" style="width:100%">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>School Name</th>
                        <th>First Name</th>
                        <th>Last Name</th>
                        <th>Email</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                        foreach ( $teacher as $user ) {
                    ?>
                    <tr>
                        <td><?php echo $i+= 1; ?></td>
                        <td><?php 
                            //Displays School Name
                            global $wpdb;
                            $teacher_email = $user->user_email;
                            echo display($teacher_email,4)
                        ?></td>
                        <td><?php echo esc_html( $user->first_name ) ?></td>
                        <td><?php echo esc_html( $user->last_name ) ?></td>
                        <td><?php echo display($teacher_email,6) ?></td> -->
                        <td><?php echo esc_html( $user->user_email ) ?></td>
                        <td>
                            <button class="btn btn-success btn-view-shelf" data-id="<?php echo esc_html( $user->ID ); ?>">View</button>
                            <button class="btn btn-info btn-update-shelf" data-id="<?php echo esc_html( $user->ID ); ?>">Edit</button>
                            <button class="btn btn-danger btn-delete-shelf" data-id="<?php echo esc_html( $user->ID ); ?>" data-email="<?php echo esc_html( $user->user_email ); ?>">Delete</button>
                        </td>
                    <tr>
                    <?php } ?>
                </tbody>
                <tfoot>
                    <tr>
                        <th>ID</th>
                        <th>School Name</th>
                        <th>First Name</th>
                        <th>Last Name</th>
                        <th>Email</th>
                        <th>Action</th>
                    </tr>
                </tfoot>
            </table>
            </div>
        </div>   
    </div>
</div>

标签: phphtmlmysqlsearchbar

解决方案


推荐阅读