Código PHP:
<?php
function paginar($actual, $total, $por_pagina, $enlace) {
$total_paginas = ceil($total/$por_pagina);
$anterior = $actual - 1;
$posterior = $actual + 1;
if ($actual>1)
$texto = "<a href=\"$enlace$anterior\">«</a> ";
else
$texto = "<b>«</b> ";
for ($i=1; $i<$actual; $i++)
$texto .= "<a href=\"$enlace$i\">$i</a> ";
$texto .= "<b>$actual</b> ";
for ($i=$actual+1; $i<=$total_paginas; $i++)
$texto .= "<a href=\"$enlace$i\">$i</a> ";
if ($actual<$total_paginas)
$texto .= "<a href=\"$enlace$posterior\">»</a>";
else
$texto .= "<b>»</b>";
return $texto;
}
$conex = mysql_connect ("localhost","root","");
mysql_select_db ("imarket",$conex);
if (!isset($pag)) $pag = 1; // Por defecto, pagina 1
$result1 = mysql_query("select count(*) from products where description like ('%$keyword%')", $conex);
list($total) = mysql_fetch_row($result1);
$tampag = 3;
$reg1 = ($pag-1) * $tampag;
$xsql = "select * from products where description like ('%$keyword%') LIMIT $reg1, $tampag";
$result = mysql_query ($xsql,$conex);
//list($total) = mysql_fetch_row($result);
if (mysql_num_rows($result)){
echo "<table border = '0'>";
echo "<tr><td>ID PRODUCT</td><td>DESCRIPTION</td></tr>";
while ($row = mysql_fetch_array($result)) {
echo "<tr><td>".$row["id_product"].
"</td><td>".$row["description"]."</td></tr>";
}
echo "</table>";
echo paginar($pag, $total, $tampag, "searching.php?pag=");
}
else
echo "¡ NO PRODUCTS IN EXISTENCE... !";
mysql_close ($conex);
?>