【问题标题】:How to add a pagination in a html table using PHP?如何使用 PHP 在 html 表格中添加分页?
【发布时间】:2016-05-19 12:28:34
【问题描述】:

我有在表格行中显示结果的 PHP sn-p。我正在尝试使用(1 2 3 4 ...10)在表格末尾进行分页。每页显示的最小行数仅为 15。

但我的代码不起作用。请帮帮我

$results_per_page = 10;
$current = get_query_var('paged') ? get_query_var('paged') : 1;
$start = ($current - 1) * $rows_per_page;
$end = $start + $rows_per_page;
$end = (sizeof($rows) < $end) ? sizeof($rows) : $end;

if (isset($_POST['list_position']) && $_POST['list_position'] != 'Select by Position'){
    $list_position= $_POST['list_position'];
    $result_position= $wpdb->get_results($wpdb->prepare("SELECT DISTINCT id, submit_time, last_name, first_name, middle_name, mobile_number, email, location, position, message FROM tablename WHERE position= '" . $list_position . "' ORDER BY position ASC", OBJECT));
        echo '<table>';
        echo '<tr>';
        $dir="";
        $file="";
        $optionId = 0;
        echo '<th>Submit Time</th>';
        echo '<th>Last Name</th>';
        echo '<th>First Name</th>';
        echo '<th>Middle Name</th>';
        echo '<th>Mobile Number</th>';
        echo '<th>Email</th>';
        echo '<th>Position</th>';
        echo '<th>Message</th>';
        echo '<th>Resume</th>';
        echo '<th>Processed?</th>';
    foreach ($result_position as $record_s){
        $optionId++;
        //$optionId = $record_s['id'];
        for ($i=$start;$i < $end ;++$i ){
        echo '<tr>';
        echo '<td id="submit_time">' . $record_s->submit_time . '</td>';
        echo '<td id="last_name">' . $record_s->last_name . '</td>';
        echo '<td id="first_name">' . $record_s->first_name . '</td>';
        echo '<td id="middle_name">' . $record_s->middle_name . '</td>';
        echo '<td id="mobile_number">' . $record_s->mobile_number . '</td>';
        echo '<td id="email">' . $record_s->email . '</td>';
        echo '<td id="position">' . $record_s->position . '</td>';
        echo '<td id="message">' . $record_s->message . '</td>';
        echo '<td id="resumeFile'.$id.'"><a href="' . $dir  . $file . '">Download Resume</a></td>';
        echo '<td id="radioOption><label for="Yes">Yes</label>
                  <input type="radio" id="processedOptionYes'.$optionId.'" name="processedOption" value="Yes" onclick="proccessedCheck('.$optionId.',\'Yes\')"/>
                  <label for="No">No</label>
                  <input type="radio" id="processedOptionNo'.$optionId.'" name="processedOption" value="No" onclick="proccessedCheck('.$optionId.',\'No\')"/></td>';
        echo '</tr>';
            }
        }
        echo '</table>';
}

【问题讨论】:

    标签: php mysql wordpress pagination


    【解决方案1】:

    如果你想尝试另一种选择jQuery 分页? https://datatables.net/examples/basic_init/zero_configuration.html 这是数据表链接,您可以轻松地在 php 中实现。

    【讨论】:

    • 我需要在服务器端进行分页
    • 是的,你也可以包括服务器端。
    • 我不想使用任何JS,PHP只在分页中使用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-04
    • 2017-09-03
    • 2013-11-05
    • 2018-08-04
    • 2015-09-02
    • 2021-08-22
    • 1970-01-01
    相关资源
    最近更新 更多