How do I create items for a virtual store type site. Pull DB items and put paging with 15 items limit.
How do I create items for a virtual store type site. Pull DB items and put paging with 15 items limit.
You want the whole job ready, right? rsrs
I'll give you a light here ..
To pull the products from the bank, use:
SELECT * FROM meus_itens
To pull only 15 items from the bank, use:
SELECT * FROM meus_itens LIMIT 15
To page the results, LIMIT receives LIMIT (Número de ítens passados), (Número de itens à mostrar)
, for example, on the one page the search should be:
SELECT * FROM meus_itens LIMIT 0, 15
Already on the two page, it should be:
SELECT * FROM meus_itens LIMIT 15, 15
Three page:
SELECT * FROM meus_itens LIMIT 30, 15
And so on, so you have to make a logic to get the number of a page and turn it into the data you want.
In PHP, to do this, just take a page number, which can be a GET parameter eg subtract 1 and multiply by the number of records you want: ((NUM_PAG - 1) * NUM_REG) strong> .. 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 have helped you kick in to complete what you want to do.