Foros del Web » Programando para Internet » PHP »

Imagenes Aleatorias (Se Repiten)

Estas en el tema de Imagenes Aleatorias (Se Repiten) en el foro de PHP en Foros del Web. Muy buenas para todos. Espero esten bien. Tengo un pequeñin problema El Script en php que les mostrare hace que me visualice 6 imagenes que ...
  #1 (permalink)  
Antiguo 13/02/2011, 10:14
 
Fecha de Ingreso: octubre-2009
Ubicación: Lima
Mensajes: 31
Antigüedad: 14 años, 6 meses
Puntos: 0
Pregunta Imagenes Aleatorias (Se Repiten)

Muy buenas para todos. Espero esten bien.

Tengo un pequeñin problema
El Script en php que les mostrare hace que me visualice 6 imagenes que tube que poner randon distintos para que me muestre las 6 imagenes pero el detalle es de que se repiten las imagenes y yo no kiero ke se repitan alguien me puede ayudar por favor.

Cita:
PD: Imagenes de prueba para que lo prueben en su localhost mas rápido.
Muchas Gracias de antemano.


Código PHP:
 <?php
$numbanners 
6//Numero de imagenes
$random1 rand(1,$numbanners);
$random2 rand(2,$numbanners); 
$random3 rand(3,$numbanners); 
$random4 rand(4,$numbanners); 
$random5 rand(5,$numbanners); 
$random6 rand(6,$numbanners); 

$img = array();
$url = array();
$txt = array();

$img[1] = "http://nahjupr.files.wordpress.com/2009/01/wordpress-logo.png?w=300";
$url[1] = "http://www.1.com";
$txt[1] = "Visita el enlace del banner 1";

$img[2] = "http://img.dinero20.com/wp-content/uploads/2010/02/joomla.png";
$url[2] = "http://www.2.com";
$txt[2] = "Visita el enlace del banner 2";

$img[3] = "http://www.psd2xhtmlcoder.com/images/osCommerceLogo.jpg";
$url[3] = "http://www.3.com";
$txt[3] = "Visita el enlace del banner 3";

$img[4] = "http://www.readwriteweb.es/wp-content/uploads/2010/12/drupal-logo.jpg";
$url[4] = "http://www.4.com";
$txt[4] = "Visita el enlace del banner 4";

$img[5] = "http://www.pcdigital.org/wp-content/uploads/2009/07/twitter-social.jpg";
$url[5] = "http://www.5.COM";
$txt[5] = "Visita el enlace del banner 5";

$img[6] = "http://cdn.alt1040.com/files/2010/05/facebook_logo.png";
$url[6] = "http://www.6.COM";
$txt[6] = "Visita el enlace del banner 6";
 
echo 
"


<a href='$url[$random1]'><img src='$img[$random1]' border='0' width='200' height='200'></a>
<a href='$url[$random2]'><img src='$img[$random2]' border='0' width='200' height='200'></a>
<a href='$url[$random3]'><img src='$img[$random3]' border='0' width='200' height='200'></a>
<a href='$url[$random4]'><img src='$img[$random4]' border='0' width='200' height='200'></a>
<a href='$url[$random5]'><img src='$img[$random5]' border='0' width='200' height='200'></a>
<a href='$url[$random6]'><img src='$img[$random6]' border='0' width='200' height='200'></a>

"
;
?>
Espero respuestas estoy muy desesperado jeje
  #2 (permalink)  
Antiguo 13/02/2011, 10:54
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: Imagenes Aleatorias (Se Repiten)

Yo haria lo siguiente:

Tener un array con la siguiente estructura:

[0] => array [ [img]=>'ruta', [url]=>'url', [txt]=>'text' ]
[1] => array [ [img]=>'ruta', [url]=>'url', [txt]=>'text' ]

etc ...
Entonces tu array seria:
Código PHP:
Ver original
  1. $imagenes = array(
  2.     array(
  3.         'img' => 'http://nahjupr.files.wordpress.com/2009/01/wordpress-logo.png?w=300',
  4.         'url' => 'http://www.1.com',
  5.         'txt' => 'Visita el enlace del banner 1'
  6.     ),
  7.  
  8.     array(
  9.         'img' => 'http://img.dinero20.com/wp-content/uploads/2010/02/joomla.png',
  10.         'url' => 'http://www.2.com',
  11.         'txt' => 'Visita el enlace del banner 2')
  12. );

Hacer un shuffle() y luego ir imprimiendo las imagenes.
  #3 (permalink)  
Antiguo 13/02/2011, 11:10
 
Fecha de Ingreso: octubre-2009
Ubicación: Lima
Mensajes: 31
Antigüedad: 14 años, 6 meses
Puntos: 0
Exclamación Respuesta: Imagenes Aleatorias (Se Repiten)

Ronruby Gracias por tu respuesta ..

Pero no se utilizar el shuffle!! y deseo que por favor me brindes la solucion si no es mucho pedir .. estare muy agradecido

Waaa
  #4 (permalink)  
Antiguo 13/02/2011, 11:16
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: Imagenes Aleatorias (Se Repiten)

Completas el array, haces el shuffle() y luego iteras:
Código PHP:
Ver original
  1. shuffle($imagenes);
  2. foreach($imagenes as $imagen) {
  3.   echo "<a href='$imagen[img]'><img src='$img[$random1]' border='0' width='200' height='200'></a>";
  4. }
  #5 (permalink)  
Antiguo 13/02/2011, 11:41
 
Fecha de Ingreso: octubre-2009
Ubicación: Lima
Mensajes: 31
Antigüedad: 14 años, 6 meses
Puntos: 0
De acuerdo Gracias!!!!!

Brother Asunto solucionado .. Muchas Gracias me salvaste

En verdad te lo agradesco .. buscare unos tutoriales para ir aprendiendo de eso.

Reitero las Gracias

Etiquetas: imagenes, aleatoria
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:11.