Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/03/2003, 23:18
nav2003
 
Fecha de Ingreso: enero-2003
Ubicación: Santiago
Mensajes: 301
Antigüedad: 21 años, 3 meses
Puntos: 1
hacer updates a varias tablas?

Hola, tengo una pregunta para expertos, haber si me ayudan de nuevo:

modificar dos tablas una a la vez en una misma página;

a continuacion coloco un ejemplo muy simple de lo que he hecho:


en el archivo query.php quiero selecciono las tablas

-----------------------------------------------------------------------------------
Código PHP:
include("conex.php");//conexion bd
$link=conexion();
$div1="divisiones";
$sec1="secciones";

/*mod viene de un vinculo de su fichero padre(donde mod=divisiones)entonces abajo solo valido si es la tabla divisiones o no*/

if($mod==$div1){
  
$result=mysql_query("select * from divisiones order by DIV_ID DESC",$link);
  echo
"<table border=1>
      <tr><td>DIVISIÓN_ID:
      </td><td>DIVISIÓN_NOMBRE:
      </td><td>BORRAR:
      </td><td>EDITAR:
      </td></tr>"
;
      while(
$row=mysql_fetch_array($result)){
          
printf("<tr><td>&nbsp;%s</td><td>&nbsp;%s&nbsp;</td><td><a href=borrar.php?id_borra=$row[DIV_ID]>Borrar</a></td><td><a href=editar.php?id_edit=$row[DIV_ID]>Editar</a></td></tr>",$row['DIVISION_ID'],$row['DIVISION_NOMBRE'],$row['DIV_ID']);
      }
  
mysql_free_result($result);
  echo
"</table>";
}

//tabla secciones
if($mod==$sec1){
$result=mysql_query("select * from secciones order by SEC_ID DESC",$link);
idem anterior......
....

-----------------------------------------------------------------------------------
Luego 

editar
.php//en este archivo tomo los datos del registro

include("conex.php");
$link=conexion();
if(
$result=mysql_query("select * from divisiones where DIV_ID=$id_edit ",$link)){
while(
$row=mysql_fetch_array($result)){
$mostrar1=$row['DIVISION_ID'];
$mostrar2=$row['DIVISION_NOMBRE'];
$mostrar3=$row['DIV_ID'];
if(
$mostrar3==$id_edit){
echo
"<form action=update.php?ide=$mostrar3 method=post>
<input type=text name=divi value=$mostrar1>
<input type=text name=divinom value=$mostrar2>
<input type=submit name=guardar value=guardar style=cursor:hand>
"
;
}
}}


lo mismo para la tabla secciones
...
bla bla
...
-----------------------------------------------------------------------------------
acá tengo el problema

update
.php
//tabla divisiones
if(!isset($mostrar3)){
$result=mysql_query("UPDATE divisiones SET DIVISION_ID='$divi', DIVISION_NOMBRE='$divinom' where DIV_ID=$ide",$link);
$id="divisiones";
header("location:query.php?mod=$id"); //dirigir a la tabla divisiones
}


//tabla secciones
if(!isset($mostrar4)){
$result=mysql_query("UPDATE secciones SET DIVISION_ID='$divi', SECCION_NOMBRE='$divinom' where SEC_ID=$ide",$link);
$id="secciones";
header("location:query.php?mod=$id");          

mi problema está en como lo hago para modificar un registro de la tabla secciones y no se mezclen, he modificado los datos de las tablas pero en el moemto de dirigir el resultado a la tabla correspondiente la envía a la otra....osea modifico la tabla divisiones correctamente pero me la envía a la tabla secciones y como no soy experto en php no logro controlar esto
__________________
Cristian...