I have a code of a plugin I made, which shows a custom table and I need to add paging.
This code does appear pagination and results, but does not work when clicking on the following pages (1, 2, 3 ... etc) but shows the same.
This is my code:
$per_page = 3;
$page = intval(get_query_var('page')); // cast to int to be on the safe side
$total_pages = ceil($wpdb->get_var("SELECT COUNT(*) FROM wp_puntos_log") / $per_page);
//use $wpdb->prepare to help against sql injection
$sql = $wpdb->prepare("SELECT * FROM wp_puntos_log LIMIT %d, %d", $page * per_page, $per_page);
$mylink = $wpdb->get_results($sql);
foreach ($mylink as $mostrar)
{
echo"
<tr>
<td>".$mostrar->punto_user_ID."</td>
<td>".$mostrar->punto_nombre."</td>
<td>".number_format($mostrar->punto_canjeados, 0, ',', '.')."</td>
<td>".cambiarFormatoFecha($mostrar->punto_fecha)."</td>";
}
echo" </tr>
</tbody>
</table>";
$big=999999999; // dummy used by 'base' below
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?page=%#%',
'current' => max( 1, $page ),
'total' => $total_pages,
) );
Took a long time trying and not working. I appreciate your help.
Greetings!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…