Re: paginador php
| From: | Carlos Macías | Date: | Sun, 08 Sep 2002 03:51:07 +0000 |
| Subject: | Re: paginador php | ||
| References: | 1 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-26606@lists.php.net to get a copy of this message | ||
Prueba con esto:
<?php require_once('Connections/registros.php'); ?>
<?php
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];
$maxRows_noticias = 2; ------->> número de registros por página
$pageNum_noticias = 0;
if (isset($HTTP_GET_VARS['pageNum_noticias'])) {
$pageNum_noticias = $HTTP_GET_VARS['pageNum_noticias'];
}
$startRow_noticias = $pageNum_noticias * $maxRows_noticias;
mysql_select_db($database_registros, $registros);
$query_noticias = "SELECT * FROM noticia_noticia";
$query_limit_noticias = sprintf("%s LIMIT %d, %d", $query_noticias,
$startRow_noticias, $maxRows_noticias);
$noticias = mysql_query($query_limit_noticias, $registros) or
die(mysql_error());
$row_noticias = mysql_fetch_assoc($noticias);
if (isset($HTTP_GET_VARS['totalRows_noticias'])) {
$totalRows_noticias = $HTTP_GET_VARS['totalRows_noticias'];
} else {
$all_noticias = mysql_query($query_noticias);
$totalRows_noticias = mysql_num_rows($all_noticias);
}
$totalPages_noticias = ceil($totalRows_noticias/$maxRows_noticias)-1;
$queryString_noticias = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_noticias") == false &&
stristr($param, "totalRows_noticias") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_noticias = "&" . implode("&", $newParams);
}
}
$queryString_noticias = sprintf("&totalRows_noticias=%d%s",
$totalRows_noticias, $queryString_noticias);
?>
<html>
<head>
<title>Documento sin título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.enlaces {
font-family: verdana;
font-size: 9pt;
color: #CC0000;
text-decoration: none;
}
-->
</style>
</head>
<body>
<table width="100%" border="0" cellspacing="2"
cellpadding="2">
<tr>
<td><p><font color="#000033" size="2"
face="verdana">|
<?php $final= $totalRows_noticias;
$regporpag=$final/$maxRows_noticias;
for($i=0;$i<$regporpag;$i++) {
if ($pageNum_noticias==$i ) { echo $i + 1 , " | " ;} else {
echo "<a class='enlaces' href='$currentPage?pageNum_noticias=" ,
$i ,
"&totalRows_noticias=" , $totalRows_noticias , "'>" , $i + 1 ,
" </a>| " ;
}} ?>
</font></p>
<table width="100%" border="0" cellspacing="2"
cellpadding="0">
<?php do { ?>
<tr>
<td height="30" align="left" valign="bottom"><font
color="#000033"
size="2" face="verdana"><?php echo $row_noticias['titular'];
?></font></td>
</tr>
<tr>
<td height="0" bgcolor="#000033"><font
color="#000033" size="2"
face="verdana"><img src="images/trans.gif" width="1"
height="1"></font></td>
</tr>
<?php } while ($row_noticias = mysql_fetch_assoc($noticias)); ?>
</table>
<p><font color="#000033" size="2" face="verdana">
</font></p>
<p> </p></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($noticias);
?>