N3lson Posted April 19, 2013 at 07:27 PM Report #504089 Posted April 19, 2013 at 07:27 PM boas tenho este código para fazer a paginação mas algo está mal, poderiam-me ajudar? //paginação $records_per_page = 20; $row = mysqli_query($conexao, "SELECT COUNT(*) FROM susp"); $total = mysqli_num_rows($row); $page_count = ceil($total / $records_per_page); $page = 1; if (isset($_GET['page']) && $_GET['page'] >= 1 && $_GET['page'] <= $page_count) { $page = (int)$_GET['page']; } $skip = ($page - 1) * $records_per_page; $resultados = mysqli_query($conexao, "SELECT * FROM susp ORDER BY data DESC LIMIT $skip, $records_per_page"); dá apenas uma página e deveria dar pelo menos 3 You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.
HappyHippyHippo Posted April 19, 2013 at 07:28 PM Report #504090 Posted April 19, 2013 at 07:28 PM $row = mysqli_query($conexao, "SELECT COUNT(*) FROM susp"); // o que retorna este SQL ? $total = mysqli_num_rows($row); // quantas linhas tem o resultado ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
N3lson Posted April 19, 2013 at 07:31 PM Author Report #504091 Posted April 19, 2013 at 07:31 PM (edited) Quantas linhas tem ou deveria ter ? Apresenta 1 Isto da paginação, não encaixei ainda 🙂 Edited April 19, 2013 at 07:34 PM by N3lson You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.
yoda Posted April 19, 2013 at 08:09 PM Report #504095 Posted April 19, 2013 at 08:09 PM O bloco de codigo apresentado é pequeno o suficiente para descobrires depressa o erro. before you post, what have you tried? - http://filipematias.info sense, purpose, direction
N3lson Posted April 19, 2013 at 08:23 PM Author Report #504096 Posted April 19, 2013 at 08:23 PM Código completo echo $table; $i=0; //paginação $records_per_page = 20; $row = mysqli_query($conexao, "SELECT COUNT(*) FROM susp"); $total = mysqli_num_rows($row); echo ($total); $page_count = ceil($total / $records_per_page); $page = 1; if (isset($_GET['page']) && $_GET['page'] >= 1 && $_GET['page'] <= $page_count) { $page = (int)$_GET['page']; } $skip = ($page - 1) * $records_per_page; $resultados = mysqli_query($conexao, "SELECT * FROM susp ORDER BY data DESC LIMIT $skip, $records_per_page"); while($tabela = mysqli_fetch_assoc($resultados)) { //print_r(strlen($tabela['soda_kg'])); // debug de variáveis echo ($i % 2)?'<tr class="odd">':'<tr class="even">';// cor alternada echo"<td>". $tabela['data']."</a></td>"; echo"<td>". $tabela['hora']."</td>"; echo"<td>". number_format($tabela['zinco'],1)."</td>"; echo"<td>". number_format($tabela['soda'],1)."</td>"; echo"<td>". number_format($tabela['minutos'],1)."</td>"; if (strlen($tabela['soda_kg']<=1)){ echo"<td>". number_format($tabela['soda_kg'],2)."</td>"; } else{ echo"<td>". number_format($tabela['soda_kg'],1)."</td>"; } echo"<td>". $tabela['abrilh']."</td>"; echo"<td>". $tabela['correct']."</td>"; echo"<td>". $tabela['lcd']."</td>"; echo"<td>". number_format($tabela['form'],1)."</td>"; echo"<td>". $tabela['resp']."</td>"; echo"</tr>"; $i++; // cor alternada } echo '</table>'; echo 'Registos: '; for ($x = 1; $x <= $page_count; ++$x) { echo '<a href="' . $_SERVER['PHP_SELF'] . '?page=' . $x . '"><span>'. $x . '</span></a> '; } You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.
HappyHippyHippo Posted April 20, 2013 at 07:32 AM Report #504115 Posted April 20, 2013 at 07:32 AM $row = mysqli_query($conexao, "SELECT COUNT(*) FROM susp"); // este SQL resulta num único registo com um número $total = mysqli_num_rows($row); // $total será sempre 1 // o que queres é $record = mysqli_fetch_array($row): $total = $record[0]; 1 Report IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
N3lson Posted April 20, 2013 at 12:07 PM Author Report #504144 Posted April 20, 2013 at 12:07 PM Obrigado HappyHippyHippo , já funciona 👍 You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.
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