Código PHP:
<HTML>
<HEAD>
<link rel="stylesheet" href="css/style.css" />
</HEAD>
<TITLE></TITLE>
<BODY>
<div id="content">
<form id="form1" name="form1" method="post" action="#">
<p align="left">
<input name="txtbuscar" type="text" id="txtbuscar" size="40" />
<span style="text-align: left">
<input name="btnbuscar" type="submit" id="btnbuscar" value="Buscar" />
</span>
</span>
</form>
<table cellpadding="0" cellspacing="0" width="100%">
<tr><thead>
<td width="15%">N Orden</td>
<td width"6%">Fecha</td>
<td width="40%">Razon Social</td>
<td width="15%">Rut Prove</td>
<td width="6%">Total</td>
</thead></tr>
<?
include("datos/conectar.php");
$vPag=$_REQUEST["pPag"];
if (empty($vPag)) $vPag = 1; // Por defecto, pagina 1
$tamPag = 10;
$regUltimo = ($vPag-1) * $tamPag;
//cantidad de registros
$datos="select count(*) FROM dbo.OC_DB inner join dbo.CLIEN_DB on dbo.OC_DB.NRUTPROV=dbo.CLIEN_DB.NREGUIST where RAZSOC like '%$txtbuscar%'";
$rs=@odbc_exec($cid, $datos);
if(odbc_fetch_into($rs, $dato))
{
$totReg = trim( $dato[0] );
}
if (isset($_POST[btnbuscar]))
{
$txtbuscar=$_POST[txtbuscar];
$datos="select top 20 CONVERT(VARCHAR(10),dbo.OC_DB.FECHA,111)as FECHA,dbo.OC_DB.NUMREG,dbo.OC_DB.NUMOC,dbo.CLIEN_DB.RAZSOC,dbo.OC_DB.RUTPROV,dbo.OC_DB.TOTAL
FROM dbo.OC_DB inner join dbo.CLIEN_DB on dbo.OC_DB.NRUTPROV=dbo.CLIEN_DB.NREGUIST where RAZSOC like '%$txtbuscar%' ORDER BY FECHA DESC";
$rs = @odbc_exec($cid, $datos);
$numCampos = odbc_num_fields($rs);
$cuentaReg=0;
odbc_fetch_row($rs,$regUltimo);
while(odbc_fetch_row($rs) && $cuentaReg<$tamPag)
{
$cuentaReg++;
echo"<tr>";
echo"<td>".odbc_result($rs,"NUMOC")."</td>";
echo"<td>".odbc_result($rs,"FECHA")."</td>";
echo"<td>".odbc_result($rs,"RAZSOC");"</td>";
echo"<td>".odbc_result($rs,"RUTPROV")."</td>";
echo"<td>".number_format(odbc_result($rs,"TOTAL"))."</td>";
echo "</tr>\n";
}
echo"<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
echo"<tr><td align=\"center\">".paginar($vPag,$totReg,$tamPag,"buscar.php?pPag=",10)."</td></tr>";
echo"</table>";
echo"</table>";
odbc_close( $cid ); // Se cierra la conexión
//echo paginar($vPag,$totReg,$tamPag,"consultas_OC3.php?pPag=",10);
exit();
}
function paginar($actual, $total, $por_pagina, $enlace, $maxenlaces=0)
{
$total_paginas = ceil($total/$por_pagina);
$anterior = $actual - 1;
$posterior = $actual + 1;
$minimo = $maxenlaces ? max(1, min($actual-ceil($maxenlaces/2),$total_paginas-$maxenlaces)): 1;
$maximo = $maxenlaces ? min($total_paginas, max($actual+floor($maxenlaces/2),$maxenlaces)): $total_paginas;
if ($actual>1)
$texto = "<a href=\"$enlace$anterior\">«</a> ";
else
$texto = "<b>«</b> ";
//if ($minimo!=1) $texto.= "... ";
if ($minimo!=1) $texto = "<a href=\"$enlace\"1>|«</a> ".$texto."... ";
for ($i=$minimo; $i<$actual; $i++)
$texto .= "<a href=\"$enlace$i\">$i</a> ";
$texto .= "<b>$actual</b> ";
for ($i=$actual+1; $i<=$maximo; $i++)
$texto .= "<a href=\"$enlace$i\">$i</a> ";
if ($maximo!=$total_paginas) $texto.= "... ";
if ($actual<$total_paginas)
$texto .= "<a href=\"$enlace$posterior\">» </a>";
else
$texto .= "<b>»</b>";
if ($maximo!=$total_paginas) $texto.= "<a href=\"$enlace$total_paginas\">»|</a> ";
$texto.="<br> Mostrando registros del ".(($actual*$por_pagina)-$por_pagina+1)." al ";
$texto.=($actual*$por_pagina)>$total?$total:($actual*$por_pagina);
$texto.= " (de un total de $total). Página $actual de $total_paginas.";
return $texto;
}
?>
</table>
</div>
</BODY>
</HTML>