t0ze Posted February 6, 2013 at 09:56 PM Report #494432 Posted February 6, 2013 at 09:56 PM Boa noite, como podem ver neste exemplo aqui http://t0ze.dynip.sapo.pt/static/ tenho uma tabela com paginação, (fazendo uso de uma classe pagination). Só que como podem ver todas as paginas são apresentadas. Já andei aqui a martelar ciclos for, mas nunca acerto... o objectivo seria: Sendo por exemplo a pagina actual = 10 mostrar apenas Previous... 7 8 9 10 11 12 13 ... Next $page = !empty($_GET['page']) ? (int)$_GET['page']: 1; //records per page $per_page = 10; $total_count = country_count_all(); $pagination = new pagination($page, $per_page, $total_count); $offset = $pagination->offset(); $total = $pagination->total_pages(); $query ="SELECT country.* FROM country LIMIT 10 OFFSET $offset"; $table = ""; $result_set = mysql_query($query); confirm_query($result_set); $table = "<table id=\"myTable\" class=\"tablesorter\"style='width:100%; border-spacing:0;'> <thead> <tr> <th>Nome</th> <th>Nome Local</th> </tr> </thead>"; while($country = mysql_fetch_array($result_set)){ $table = $table."<tr><td>".$country['Name']."</a></td> <td >". $country['LocalName']."</td> </tr>"; } echo $table; if ($pagination->total_pages()>1) { if ($pagination->has_previous_page()) { $previouspage = $pagination->previous_page(); echo " <a href='index.php?page=$previouspage'> Previous </a> "; } for ($i=1; $i <= $total; $i++) { if ($i == $page) { echo " <a href=\"index.php?page={$i}\"> <b><u>{$i}</u></b> </a>"; }else{ echo " <a href=\"index.php?page={$i}\"> {$i} </a>"; } } if ($pagination->has_next_page()) { $nextpage = $pagination->next_page(); echo " <a href='index.php?page=$nextpage'> Next </a> "; } }
yoda Posted February 6, 2013 at 11:32 PM Report #494436 Posted February 6, 2013 at 11:32 PM (edited) $start_pag_num = ($page - 3) < 1 ? 1 : $page - 3; $end_pag_num = ($page + 3) > $total ? $total : $page + 3; for ($i=$start_pag_num; $i <= $end_pag_num; $i++) { Edited February 6, 2013 at 11:34 PM by yoda 1 Report before you post, what have you tried? - http://filipematias.info sense, purpose, direction
t0ze Posted February 7, 2013 at 12:45 AM Author Report #494439 Posted February 7, 2013 at 12:45 AM Obrigado yoda.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now