Ver Mensaje Individual
  #2 (permalink)  
Antiguo 11/03/2007, 16:13
santhy
 
Fecha de Ingreso: febrero-2006
Mensajes: 134
Antigüedad: 18 años, 2 meses
Puntos: 10
Re: Como generar localizador de reserva aleatorio tipo ZX32B1

Mejor que lo hagas programándolo y no dejando a MySQL solo con eso...

Si usas php podrías usar algo como
Código PHP:

function genera_aleatorio() {
$cars = array('0''1''2''3''4''5''6''7''8''9',
 
'A''B''C''D''E''F''G''H',
 
'I''J''K''L''M','N','O','P','Q',
 
'R','S','T','U','V','W','X','Y','Z');

$longitud 6;


$aleat '';
for(
$i 0$i $longitud$i++) {
$aleat .= $cars[rand(0count(cars))];
}

// Ahora consultas si ya existe.
// Si existe, vuelves a llamar a la funcion

$r mysql_query(SELECT FROM `tutablaWHERE id $aleat);
if(empty(
mysql_fetch_array($r))) {
 return 
$aleat
} else {
 return 
genera_aleatorio(); 
}