Ver Mensaje Individual
  #3 (permalink)  
Antiguo 05/03/2008, 21:54
Avatar de ranceis
ranceis
 
Fecha de Ingreso: septiembre-2006
Mensajes: 42
Antigüedad: 17 años, 7 meses
Puntos: 0
Re: Numero de Datos Aleatorios desde BD (sin repetir registros)

hey aqui un ejemplo que hice con manejo de bases de datos.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<?php

require "Connections/conexion.php"; //establesco conexion

$aleatorio1=rand(1,3); //aqui declaro 2 randoms 2 numeros aleatoreos

$aleatorio2=rand(1,3);
$max=3;
if($aleatorio1==$aleatorio2){ //aca nomas para que no se repita mucho el aleatorio.. ya tu varias o lo quitas
$aleatorio2=$aleatorio2+1;

if($aleatorio2<$max){
$aleatorio2=$aleatorio2-1;
}

}


$sqlC=mysql_query("SELECT * FROM prueba.camiones WHERE idCAMIONES='$aleatorio1'"); //primera consulta de camiones fijate que uso el aleatorio 1 para hacer que me tire un numero al azar

$rc=mysql_fetch_array($sqlC);

$camiones=$rc['camiones']; //variable que contiene el resultado de mi consulta

$sqlC=mysql_query("SELECT * FROM prueba.empresas WHERE idEMPRESAS=$aleatorio2"); //mismo que empresas

$rc=mysql_fetch_array($sqlC);

$empresas=$rc['empresas'];



?>
<table width="200" border="1"> <!--aqui tabla para pintar los 2 resultados-->
<tr>
<td><?php echo $camiones; ?>&nbsp;</td>
<td><?php echo $empresas; ?>&nbsp;</td>
</tr>
</table>
</body>
</html>


Espero y te sirva.. xD