Tema: Buscador
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/06/2010, 15:17
markmb
 
Fecha de Ingreso: octubre-2009
Ubicación: En el ordenador
Mensajes: 504
Antigüedad: 14 años, 6 meses
Puntos: 10
Buscador

Llevo todo el día con el mismo script y no consigo que vaya bien:

http://www.webexperto.com/articulos/...simple-en-php/

(Este es el buscador original)
Va bien, pero es para un trabajo que estoy haciendo en una web (que me han pedido que no ponga) y lo que hace es buscar coches en 2 bases de datos, por tanto, he hecho muchas modificaciones al script:

Código PHP:
require_once('info.php');
$conn = mysql_connect("localhost", $usuario, $clave);
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_Rs = 14;
$pageNum_Rs = 0;
if (isset($_GET['pageNum_Rs'])) {
$pageNum_Rs = $_GET['pageNum_Rs'];
}
$startRow_Rs = $numpag * $maxRows_Rs;
/*Función de ordenar*/
/*Los particulares:*/
/*Las empresas:*/
/*Juntar los resultados*/
$row = array();
mysql_select_db($baseDeDatos, $conn);
while ($row_Rs = mysql_fetch_assoc($Rs)){
    $row[] = $row_Rs;
}
mysql_select_db($baseDeDatos2, $conn);
while ($row_Rse = mysql_fetch_assoc($Rse)){
    $row[] = $row_Rse;
}
/*Ordenar resultados*/
$row_Rs = ordenar_array($row, 'fecha', SORT_DESC) or die ('ERROR!');
/*Paginar*/
if (isset($_GET['totalRows_Rs'])) {
$totalRows_Rs = $_GET['totalRows_Rs'];
} else {
$totalRows_Rs = count($row_Rs);
}
$totalPages_Rs = ceil($totalRows_Rs/$maxRows_Rs)-1;
$queryString_Rs = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Rs") == false &&
stristr($param, "totalRows_Rs") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Rs = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Rs = sprintf("&totalRows_Rs=%d%s", $totalRows_Rs, $queryString_Rs);
?>
<html>
<head>
<title>cochesentenerife.es - Resultado de búsqueda</title>
<link href="css/hoja-de-estilo.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="575" border="0" align="center" cellpadding="0" cellspacing="0">
<?php foreach ($row_Rs as $valor){     ?>
<div id="resultados">
    <h3>Resultados:</h3>
    <?php
    $imgs 
explode(','$valor['imgs']);
    
?>
    <div class="resultado">
        <img src="thmbs/<?php echo $imgs[0]; ?>" />
        <span class="marca"><?php echo $valor['marca']; ?> <?php echo $valor['modelo']; ?></span>
        <span class="precio"><?php echo $valor['precio']; ?> &euro;</span>
        <?php if (isset($valor['usuario_id'])){ ?>
            <a class="detalles" href="verautoempresa.php?id=<?php echo $valor['coche_id']; ?>">Ver detalles.</a>
        <?php }else{ ?>
            <a class="detalles" href="verauto.php?id=<?php echo $valor['coche_id']; ?>">Ver detalles.</a>
        <?php ?>
        <p><?php echo nl2br(htmlentities(substr($valor['observaciones'], 0130 ))); ?>...</p>
        <hr />
    </div>
</div>
<?php ?>
</table>
<table>
<tr>
<td><table width="590" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="10"><table width="590" height="34" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#FBFBFB"><td width="65" class="texto-chico"><div align="center">
<?php if ($pageNum_Rs 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Rs=%d%s"$currentPage0$queryString_Rs); ?>" class="txt-paginador"><strong>Primero</strong></a>
<?php // Show if not first page ?>
</div></td>
<td width="80" class="texto-chico"><div align="center">
<?php if ($pageNum_Rs 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Rs=%d%s"$currentPagemax(0$pageNum_Rs 1), $queryString_Rs); ?>" class="txt-paginador"><strong> &lt; Anterior</strong></a>
<?php // Show if not first page ?>
</div></td>
<td width="312"><div align="center" class="titCategoria"><strong>
<?php
$last
=$totalPages_Rs+1;
$current=$pageNum_Rs+1;
for (
$i 1$i <= $last$i++) {
if(
$current==$i){
echo 
$i." .";
}else{
?>
<a href="<?php printf("%s?pageNum_Rs=%d%s"$currentPagemin($totalPages_Rs$i-1), $queryString_Rs); ?>"><?php echo $i;?></a>
<?php
}
}
?>
</strong></div></td>
<td width="77"><div align="right" class="txt-paginador">
<?php if ($pageNum_Rs $totalPages_Rs) { // Show if not last page ?>
<div align="center"><a href="<?php printf("%s?pageNum_Rs=%d%s"$currentPagemin($totalPages_Rs$pageNum_Rs 1), $queryString_Rs); ?>" class="txt-paginador"><strong>Siguiente &gt; </strong></a> </div>
<?php // Show if not last page ?>
</div></td>
<td width="56"><div align="right">
<?php if ($pageNum_Rs $totalPages_Rs) { // Show if not last page ?>
<div align="center" class="txt-paginador"><span class="titCategoria"><a href="<?php printf("%s?pageNum_Rs=%d%s"$currentPage$totalPages_Rs$queryString_Rs); ?>" class="txt-paginador"><strong>Ultimo</strong></a></span> </div>
<?php // Show if not last page ?>
</div></td>
</tr>
</table><div align="left"></div>
<table width="590" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td height="26"><div align="right" class="text-marroncito"><strong>Est&aacute; en la Página:
<?php
if($totalPages_Rs==0){
echo 
"0/0";
}else{
echo 
$pageNum_Rs+1;
echo 
"/";
echo 
$totalPages_Rs+1;
}
?>
</strong></div></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result
($Rs);
?>
Aclaraciones: Iba a poner todo el script, pero no me deja, da un post demasiado largo. Donde pone "Función de ordenar", es una función encontrada en el wiki de este foro, para ordenar un array bidimensional, eso va bien, no os lo miréis mucho. Donde pone "Los particulares" y "Las empresas", es el trozo donde busca en las 2 bds los datos de la búsqueda.

Lo que ocurre es que al buscar (va perfectamente eso) si solo es 1 página, va bien, pero cuando deberian ser 2 páginas, sale solo 1, y cuando deberian ser 3, salen 2. Además, al darle a siguiente, o al número de la página siguiente, salen los mismos resultados.

Me podeis ayudar!!!