我有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>';
}
答案 0 :(得分:1)
jQuery分页如果你想尝试另一种选择? https://datatables.net/examples/basic_init/zero_configuration.html这是您可以在php中轻松实现的数据表链接。