Hola, mira en este ejemplo puede servirte

insert into tabla_RGB values ((select 255 * random()),(select 255 * random()),(select 255 * random()));

saludos...


On 12/06/2012 07:49 PM, Jose Mercedes Venegas Acevedo wrote:
buen dia a todos tengo este inconveniente en mi sistema estoy haciendo varias operaciones dentro del begin commit

lo que estoy haciendo es generando grafico de sectores y los pinto con un color aleatorio como ven en la linea 2 al final debo introducir el campo color que debe tener esta forma
ejemplo:
190 200 150
como se ve en la linea 3 hago esto enviando 3 variables de php $r $g $b con espacios sin embargo dependiendo de las lineas 2 y 3

en la las lineas 6 y 7 debo volver a poner un color sin embargo aqui ya no es un registro sino n registros asi que debo colocar un numero aleatorio para pintar de diferentes colores cada registro sin embargo debo asegurarme que los 3 numeros ingresados con espacios esten entre 0 y 255 que son los valores validos para rgb alguien puede darme una idea como podria hacer esto?

1   $query = 'BEGIN; ';

2 $query .= 'insert into maestro_distribucion (usuario,fh_inicio,fh_fin,estado,glosa,fecha_inicio,fecha_fin,hora_ini,hora_fin,the_geom,color ) '; 3 $query .= "values ('$usuario','$fh_ini','$fh_fin',3,'$red','$fechaIni','$fechaFin','$horaIni','$horaFin',st_geomfromtext('SRID=32717;POLYGON((".$coords."))'),'$r $g $b');";

4 $query .= 'insert into detalle_distribucion (id_mdistribucion,id_suministro,the_geom) '; 5 $query .= "select currval('maestro_distribucion_id_seq'),l.id <http://l.id>,l.the_geom from cat_lote l where st_contains(st_geomfromtext('SRID=32717;POLYGON((".$coords."))'),l.the_geom); ";

6 $query .= 'INSERT INTO maestro_distribucion (usuario,fh_inicio,fh_fin,the_geom,estado,glosa,fecha_inicio,fecha_fin,hora_ini,hora_fin,anio,color) '; 7 $query .= 'select m2.usuario,m2.fh_inicio,m2.fh_fin,ST_Difference(m2.the_geom,m1.the_geom),2,m2.glosa,m2.fecha_inicio,m2.fecha_fin,m2.hora_ini,m2.hora_fin,m2.anio ';
8   $query .= 'from maestro_distribucion m1,maestro_distribucion m2 ';
9 $query .= "where st_intersects(m1.the_geom,m2.the_geom) and m1.estado = 3 and m2.estado != 3;";

10 $query .= 'insert into detalle_distribucion (id_mdistribucion,id_suministro) '; 11 $query .= 'select m.id <http://m.id>,l.id <http://l.id> from cat_lote l,maestro_distribucion m where st_contains(m.the_geom,l.the_geom) and m.estado = 2; ';

12 $query .= 'update maestro_distribucion set estado = 0 ';
13 $query .= 'FROM (SELECT m2.id <http://m2.id> FROM maestro_distribucion m1,maestro_distribucion m2 '; 14 $query .= 'WHERE m1.estado = 2 and m2.estado = 1 and st_contains(m2.the_geom,m1.the_geom)) as bb '; 15 $query .= 'WHERE bb.id <http://bb.id> = maestro_distribucion.id <http://maestro_distribucion.id>; ';

16 $query .= 'update maestro_distribucion set estado = 1 where estado = 2 or estado = 3; ';

17 $query .= "COMMIT;";

--
José Mercedes Venegas Acevedo
cel: Mov. 949808846

mails: [email protected] <mailto:[email protected]>
[email protected] <mailto:[email protected]>

PHP Spanish Docs translator member.
http://www.php.net/manual/es/index.php




10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS 
INFORMATICAS...
CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION

http://www.uci.cu
http://www.facebook.com/universidad.uci
http://www.flickr.com/photos/universidad_uci

Responder a