Ver Mensaje Individual
  #4 (permalink)  
Antiguo 11/07/2009, 14:01
cara_luna
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Cómo puedo mostrar 4 registros aleatorios con mysql y php

Cita:
Iniciado por wilar Ver Mensaje
a q te refieres en series del 0 al 4?.. probe tu codigo y solo me vota 4 registros.....
Gracias por responder, me refiero a que algunas veces me carga 2 resultados otras veces 3, otras 0 ó 1.

En realidad no sé mucho de php por lo que me he guiado por lo que he ido leyendo aquí y en otros foros,

El codigo lo he cortado para facilitar el entendimiento pero es como el siguiente:
Código HTML:
$registros=mysql_query("select * from publicacion order by RAND() limit 4", $conexion) or 
           die("Problemas en el select:".mysql_error());                     

while ($reg=mysql_fetch_array($registros)){

   $publicacion_id=$reg['publicacion_id'];
   $fecha_final=$reg['fecha_final'];
   $imagen1=$reg['imagen1'];
   $destacada=$reg['destacada'];
   $activa=$reg['activa']; 

   if ( $imagen1 == "" ) {
$imagen1 = "imag/no_imagen.png";}

if ( $destacada != "" ) { 
$destaque = '<div align="center">
  <center>
  <table border="0" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="0" width="353" height="137">
<tr>
<td align="center" height="137" width="358"><div align="center">
  <center>
  <table border="0" width="340" style="border:3px outset #000080; border-collapse: collapse" height="124" bgcolor="#FFFFFF">
<tr>
<td width="118" height="21">
<p align="center">&nbsp;</td>
</tr>
<tr>
<td width="139" height="98" bgcolor="#FFFFFF">
<p align="center">
<a href="../post/ver.php?publicacion_id='.$publicacion_id.'" style="text-decoration: none">
<img border="0" src="../post/imagen/al/public/'.$imagen1.'" width="94" height="94"></a></td>
</tr>
</table></center>
</div></td>
</tr>
</table></center>
</div';}
else{
$destaque = "";}

if ( $activa == "si" ) {
$postear = $destaque;}
else {
$postear = "";}

$fecha_actual = date("m/d/Y  h:i:s");

if (  $restan_unidades <= "0" )
 { $postear = "";}
if ($fecha_actual > $fecha_final) {
$postear = "";}
  
  echo $postear;
}
?>