gpt4 book ai didi

php - 如何使用 PHP 在 html 表格中添加分页?

转载 作者:行者123 更新时间:2023-11-29 11:31:35 24 4
gpt4 key购买 nike

我有在表行中显示结果的 PHP 片段。我正在尝试使用 (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>';
}

最佳答案

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

关于php - 如何使用 PHP 在 html 表格中添加分页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37313895/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com