2
How I create items for a web shop type site. Pull BD items and place 15-item limit pagination.
2
How I create items for a web shop type site. Pull BD items and place 15-item limit pagination.
1
You want all the work done, right ? rsrs
I’ll give you a light here ..
To pull the products from the bank, it is used:
SELECT * FROM meus_itens
To pull only 15 items from the bench, use:
SELECT * FROM meus_itens LIMIT 15
To paginate the results, the LIMIT receives LIMIT (Número de ítens passados), (Número de itens à mostrar)
, for example on the page one the research should be:
SELECT * FROM meus_itens LIMIT 0, 15
Already on the page two, must be:
SELECT * FROM meus_itens LIMIT 15, 15
Page three:
SELECT * FROM meus_itens LIMIT 30, 15
And so on, soon, you will have to make a logic to take the number of a page and turn into the data you want.
In PHP, to do this just take a page number, which can be a GET parameter for example, subtract 1 and multiply by the number of records you want: ((NUM_PAG - 1) * NUM_REG) .. Ex:
<?php
@$pag = $_GET["pagina"];
$pagina = ( empty($pag) ? 1 : ( is_numeric($pag) && $pag > 0 ) ? (int) $pag : 1 ); // if inline
// verificando se o GET não está vazio, se é numero e maior que zero, se não, a variável recebe 1
$registros = 15;
// mágica do limit
$limit = ($pagina - 1) * $registros;
// query fica assim
$query = "SELECT * FROM meus_itens LIMIT ".$limit.", ".$registros;
echo $query;
// assumindo que $_GET["pagina"] seja um, seria impresso:
// SELECT * FROM meus_itens LIMIT 0, 15
I hope I helped in the initial kick so you complete what you want to do.
Browser other questions tagged php html mysql
You are not signed in. Login or sign up in order to post.
What have you implemented? .
– tkmtts