Ver Mensaje Individual
  #2 (permalink)  
Antiguo 20/02/2010, 10:39
Avatar de CHuLoSoY
CHuLoSoY
 
Fecha de Ingreso: febrero-2002
Ubicación: Ribeira (Galicia)
Mensajes: 1.900
Antigüedad: 22 años, 2 meses
Puntos: 29
Respuesta: como Limitar un while a 6 resultados??

El limit está mal. Tienes que indicarle dónde empieza y cuántos registros a partir de ahí:

Código PHP:
Ver original
  1. $consulta=mysql_query("SELECT * FROM cancion order by can_id desc LIMIT 0,6");

Si lo quieres hacer en el while:
Código PHP:
Ver original
  1. while ($a=mysql_fetch_array($consulta))
  2.             {
  3.             $cont ++;
  4.             $id=$a['can_id'];
  5.             $cancion=$a['can_nom'];
  6.             $artista=$a['can_art'];
  7.             $foto="musica1/".$id.".jpg";
  8.             if (file_exists($foto))
  9.                 {
  10.                     $s="<img border='0' height='80' width='60' alt='$cancion $artista' src=".$foto." />";
  11.                 }
  12.             else{
  13.                     $s="<img border='0' height='80' width='60' alt='$cancion $artista' src='imagenes/Vista147.png' />";
  14.                 }
  15. if($cont==6) { break; } // sólo tienes que cortarlo
  16.                
  17.             echo "<tr><td>".$s."</td><td>".$s."</td><td>".$s."</td></tr>";
  18.             }
__________________
ESQUIO Dominios y Hosting
Las mejores características con los mejores precios.

Última edición por CHuLoSoY; 20/02/2010 a las 10:46