Angela_Santos Posted June 13, 2013 at 11:35 AM Report #512576 Posted June 13, 2013 at 11:35 AM (edited) Este código abaixo é para passar para a pagina 2 e assim sucessivamente dependendo do numero de produtos tiver na bd, sendo que so quero apresentar 8 em cada pagina. Este código tem algo certo. Mas não troca para a seguinte quando chega aos 8 e existe mais produtos. será que me pode ajudar? $n=0; $pagina=0; $pagina = array_key_exists('pagina', $_REQUEST) ? (int) $_REQUEST['pagina'] : 1; $pagina = array_key_exists('pagina', $_REQUEST) ? (int) $_REQUEST['pagina'] : 2; $registosPorPagina = array_key_exists('produto_id', $_REQUEST) ? (int) $_REQUEST['produto_id'] : $n; $offset = $pagina > 1 ? ($pagina * $registosPorPagina - $registosPorPagina) : 0; $limit = $registosPorPagina; $offset = $pagina > 2 ? ($pagina * $registosPorPagina - $registosPorPagina) : 0; $limit = $registosPorPagina; $sql = "SELECT * FROM produtos ORDER BY produto_id LIMIT $offset, $limit"; $sql = "SELECT COUNT(*) AS n FROM produtos"; $anterior = $pagina > 1 ? $pagina - 1 : 1; $seguinte = $pagina + 1; print "<a href='" . $_SERVER['PHP_SELF'] . "?NumRegistos=4&pagina=" . $anterior . "'>Página Anterior</a><BR/>"; print "<a href='" . $_SERVER['PHP_SELF'] . "?NumRegistos=4&pagina=" . $seguinte . "'>Página Seguinte</a>"; ?> Edited June 13, 2013 at 11:42 AM by Angela_Santos
pikax Posted June 13, 2013 at 11:39 AM Report #512581 Posted June 13, 2013 at 11:39 AM onde e' que estas a executar as querys? Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."
I-NOZex Posted June 13, 2013 at 11:41 AM Report #512583 Posted June 13, 2013 at 11:41 AM onde e' que estas a executar as querys? bingo 😄 e ja agora, usa a tag CODE=PHP sfv B2R » Beat2Revolution v3.0b | Regista e divulga-nos beat2revolution.net
Angela_Santos Posted June 13, 2013 at 11:44 AM Author Report #512584 Posted June 13, 2013 at 11:44 AM executar como assim? Sou novata ta? ando a aprender a mecher no p@p quanto mais haha
pikax Posted June 13, 2013 at 11:46 AM Report #512585 Posted June 13, 2013 at 11:46 AM tens que executar o sql, com por exemplo com a funcao mysqli_query Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."
yoda Posted June 14, 2013 at 12:40 AM Report #512798 Posted June 14, 2013 at 12:40 AM (edited) <?php $pagina = array_key_exists('pagina', $_REQUEST) ? (int) $_REQUEST['pagina'] : 1; $registosPorPagina = 8; $offset = $pagina > 1 ? ($pagina * $registosPorPagina - $registosPorPagina) : 0; $limit = $registosPorPagina; $sql = "SELECT * FROM produtos ORDER BY produto_id LIMIT $offset, $limit"; $sql2 = "SELECT COUNT(*) AS n FROM produtos"; $anterior = $pagina > 1 ? $pagina - 1 : 1; $seguinte = $pagina + 1; print "<a href='" . $_SERVER['PHP_SELF'] . "?NumRegistos=4&pagina=" . $anterior . "'>Página Anterior</a><BR/>"; print "<a href='" . $_SERVER['PHP_SELF'] . "?NumRegistos=4&pagina=" . $seguinte . "'>Página Seguinte</a>"; Edited June 14, 2013 at 12:40 AM by yoda 1 Report before you post, what have you tried? - http://filipematias.info sense, purpose, direction
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