Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/08/2010, 20:38
varuk
 
Fecha de Ingreso: abril-2004
Mensajes: 107
Antigüedad: 20 años
Puntos: 0
Exclamación Problemilla con función rand en php

Hola.

Mirad, tengo este código que lo que hace es cambiar el fondo de una web según el número que salga. Sin embargo este código que veis aquí no va.

<?php
$result_random=rand(1, 3);
if($result_random=1){ ?>
<body style="background: #FFF url(fondos-norte/fondo-no-es-lo-que-era.jpg) no-repeat center top">
<?php }
elseif($result_random=2){ ?>
<body style="background: #FFF url(fondos-norte/fondo-galiza-verde-chan.jpg) no-repeat center top">
<?php }
elseif($result_random=3){ ?>
<body style="background: #FFF url(fondos-norte/fondo-marichalar-style.jpg) no-repeat center top">
<?php } ?>


Por el contrario, si lo pongo de esta forma, con el signo "<=", entonce sí que va. ¿Por qué pasa eso?

<?php
$result_random=rand(1, 4);
if($result_random<=2){ ?>
<body style="background: #FFF url(fondos-norte/fondo-no-es-lo-que-era.jpg) no-repeat center top">
<?php }
elseif($result_random<=3){ ?>
<body style="background: #FFF url(fondos-norte/fondo-galiza-verde-chan.jpg) no-repeat center top">
<?php }
elseif($result_random<=4){ ?>
<body style="background: #FFF url(fondos-norte/fondo-marichalar-style.jpg) no-repeat center top">
<?php } ?>



Muchas gracias