Foros del Web » Programando para Internet » PHP »

ayuda con un case

Estas en el tema de ayuda con un case en el foro de PHP en Foros del Web. hola a tdos una pregunta lo que pasa que tengo un case en el que siempre y cuando el idtipo sea igual a 1 me ...
  #1 (permalink)  
Antiguo 03/02/2010, 16:44
 
Fecha de Ingreso: agosto-2009
Ubicación: tlalnepantla
Mensajes: 97
Antigüedad: 14 años, 8 meses
Puntos: 0
ayuda con un case

hola a tdos una pregunta lo que pasa que tengo un case en el que siempre y cuando el idtipo sea igual a 1 me debe de insertar 4 filas en una tabla pero cuando lo ejecuto la primera insercion la hace bien pero la 2,3, y 4 me marca un error por duplicar la llave primaria de la tabla espero me puedan ayudar con esto por favor aqui les pongo el codigo si hay alguna otra forma de hacerlo espero me la puedan decir

//INSERTAMOS EN PRS_ATRIBUTOS_DETALLE
//VERIFICAR SI HAY DATOS EN LA TABLA PRS_ATRIBUTOS_DETALLE

$validados= "SELECT MAX(idprs_atrib_detalle) AS idprs_atrib_detalle FROM prs_atributos_detalle";
$resmayordos=pg_query($connection,$validados) or die ("error en la consulta $validados");
if ($maydos = 1 )
{
$maydos = pg_fetch_object($resmayordos, 0) ;
//SE GUARDA COMO VARIABLE PARA PODER UTILIZARLO
$idprs_atrib_detalle = $maydos ->idprs_atrib_detalle;
}
if ($idprs_atrib_detalle<0) //SI EL RESULTADO ES NULO INICIALIZAMOS EN 0
{
$idprs_atrib_detalle == 0;
}
else //DE LO CONTRARIO INCREMENTA EN 1
{
$idprs_atrib_detalle ++; //INCREMENTA $IDPRS_SOLICITUDES EN 1
}
//OBTENEMOS EL ID DE LA TABLA ANTERIOR
$maxdos="SELECT MAX(id_detallesolicitud) AS id_detallesolicitud FROM prs_detalle_solicitud";
$mayordos=pg_query($connection,$maxdos) or die ("error en $maxdos");
if ($resultdos = 1 )
{
$resultdos = pg_fetch_object($mayordos, 0) ;
$id_detallesolicitud = $resultdos ->id_detallesolicitud;
}
//OBTENEMOS LOS ID DE LOS ATRUBUTOS COMPARANDOLOS CON EL IDTIPO
$bene="SELECT id_atributo FROM prs_atributos_solicitud WHERE idtipo=$idtipo AND nombreatributo='beneficiario'";
$benef=pg_query($connection,$bene) or die ("error en ");
if ($rbenef = 1 )
{
$rbenef = pg_fetch_object($benef, 0);
$beneficiar = $rbenef ->id_atributo;
}

$par="SELECT id_atributo FROM prs_atributos_solicitud WHERE idtipo=$idtipo AND nombreatributo='parentesco'";
$parent=pg_query($connection,$par) or die ("error en ");
if ($rparent = 1 )
{
$rparent = pg_fetch_object($parent, 0);
$parentes = $rparent ->id_atributo;
}

$fec="SELECT id_atributo FROM prs_atributos_solicitud WHERE idtipo=$idtipo AND nombreatributo='fecha'";
$fech=pg_query($connection,$fec) or die ("error en ");
if ($rfech = 1 )
{
$rfech = pg_fetch_object($fech, 0);
$fecha2 = $rfech ->id_atributo;
}

$imp="SELECT id_atributo FROM prs_atributos_solicitud WHERE idtipo=$idtipo AND nombreatributo='importe'";
$import=pg_query($connection,$imp) or die ("error en ");
if ($rimport = 1 )
{
$rimport = pg_fetch_object($import, 0);
$importe2 = $rimport ->id_atributo;
}

switch ($idtipo)
{
case ($idtipo == 1):

$id1="INSERT INTO prs_atributos_detalle (idprs_atrib_detalle,id_detallesolicitud,id_atribu to,valor)
VALUES ($idprs_atrib_detalle,$id_detallesolicitud,$benefi ciar,'$beneficiario')";
pg_query($connection,$id1);

$id2="INSERT INTO prs_atributos_detalle (idprs_atrib_detalle,id_detallesolicitud,id_atribu to,valor)
VALUES ($idprs_atrib_detalle,$id_detallesolicitud,$parent es,'$parentesco')";
pg_query($connection,$id2);

$id3="INSERT INTO prs_atributos_detalle (idprs_atrib_detalle,id_detallesolicitud,id_atribu to,valor)
VALUES ($idprs_atrib_detalle,$id_detallesolicitud,$fecha2 ,'$fecha')";
pg_query($connection,$id3);

$id4="INSERT INTO prs_atributos_detalle (idprs_atrib_detalle,id_detallesolicitud,id_atribu to,valor)
VALUES ($idprs_atrib_detalle,$id_detallesolicitud,$import e2,'$importe')";
pg_query($connection,$id4);
break;
}

espero me puedan ayudar por favor

Etiquetas: case
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:05.