How to add a pagination properly using PHP?
-
I have a custom page template with html table.
I wrote a PHP for numeric pagination (e.g. 1 2 3 4 … 9 10) in a html table. But the snippet is not working. I got only a blank table and no pagination.
Here’s the snippet:
$rows_per_page = 2;
$current = (intval(get_query_var(‘paged’))) ? intval(get_query_var(‘paged’)) : 1;$pagination_args = array(
‘base’ => @add_query_arg(‘paged’,’%#%’),
‘format’ => ”,
‘total’ => ceil(sizeof($rows)/$rows_per_page),
‘current’ => $current,
‘show_all’ => false,
‘type’ => ‘plain’,
);if($wp_rewrite->using_permalinks())
$pagination_args[‘base’] = user_trailingslashit(trailingslashit(remove_query_arg(‘s’,get_pagenum_link(1))) . ‘page/%#%/’, ‘paged’);if(!empty($wp_query->query_vars[‘s’]))
$pagination_args[‘add_args’] = array(‘s’=>get_query_var(‘s’));echo paginate_links($pagination_args);
$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, process_resume, message, attachment_resume_id FROM resume_databank 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>Location</th>’;
echo ‘<th>Position</th>’;
echo ‘<th>Message</th>’;
echo ‘<th>Resume</th>’;
echo ‘<th>Processed?</th>’;
foreach ($result_position as $record_s){
$optionId++;
for ($i=$start;$i < $end ;++$i){
$record_s = $result_position[$i];
//$optionId = $record_s[‘id’];
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=”location”>’ . $record_s->location . ‘</td>’;
echo ‘<td id=”position”>’ . $record_s->position . ‘</td>’;
echo ‘<td id=”message”>’ . $record_s->message . ‘</td>’;
echo ‘<td id=”resumeFile’.$optionId.'”>attachment_resume_id) . ‘>Download Resume</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>’;
}
- The topic ‘How to add a pagination properly using PHP?’ is closed to new replies.