PHP - mostrar datos de dos tablas con select y registrar en otra la relacion

 
Vista:
sin imagen de perfil

mostrar datos de dos tablas con select y registrar en otra la relacion

Publicado por moreira (3 intervenciones) el 21/06/2014 08:38:02
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

mostrar datos de dos tablas con select y registrar en otra la relacion

Publicado por moreira (3 intervenciones) el 21/06/2014 08:46:23
necesito mostrar infor de dos tablas con los controles select, una vez seleccionados necesito que los id de las tablas se registren en otra tabla.

tengo el siguiente codigo:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
 
require'../class/sessions.php';
$objses = new Sessions();
$objses->init();
 
$user = isset($_SESSION['usuario']) ? $_SESSION['usuario'] : null ;
 
if($user == ''){
	header('Location: http://localhost/sinfa/index.php?error=2');
}
 
?>
<?php
 
 
//realizamos la conexión a la base de datos
$objCon = new Connection();
$objCon->get_connected();
 
 
 
//consultamos el listado de las lineas!!
 
 
		$tipop="SELECT id_categoria, categoria FROM categorias order by id_categoria";
		$result1=mysql_query($tipop);
 
		$tipopu="SELECT * FROM lineas order by linea";
		$result2=mysql_query($tipopu);
		//$linea=$_POST['linea']; $categoria=$_POST['categoria'];
 
 
		//$resultx = mysql_query ("select id_categoria from categorias where categoria = '$categoria'" ) or die("Error en la consulta SQL");
		//$resulty = mysql_query ("select * from lineas where linea = '$linea'" ) or die("Error en la consulta SQL");
?>
 
 
<!DOCTYPE html>
<html lang="es">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Modulo de Configuración!!</title>
		<link rel="stylesheet" href="css3menu/style.css" type="text/css" /><style type="text/css">._css3m{display:none}</style>
 
    </head>
 
     <body style="background-color:#EBEBEB">
	<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#333399">
  <tr>
    <td width="51%" bgcolor="#333399" class="normaltextfield"><div align="left"><font color="#FFFFFF" size="2"><strong>Bienvenid@s &nbsp;<?php  echo $_SESSION['usuario'];?></strong></font></div></td>
    <td width="49%" bgcolor="#333399" class="normaltextfield"><div align="right"><font color="#FFFFFF" size="2"><strong>Hoy: 
        <?php echo date("d/m/Y");?> &nbsp;|&nbsp;&nbsp;Cerrar Sesión</strong></font></div></td>
  </tr>
   </table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#333399">
     <tr><td><h1><a href="" id="logo">SINFA</a></h1></td>
   </tr>
</table>
         <table width="80%"  border="0" align="center"  cellpadding="0" cellspacing="0">
    <tr bgcolor="#EAEAEA"> 
    <td width="86%" height="75%" valign="top">
 
	 <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
        <tr><h3 align="center">Nueva relación de Cateogoria-Linea</h3></tr>
		<tr>
	    <form id="RegForm" name="newcateglinea" action="new_categlinea_exe.php" method="post">
	    <table bgcolor="" width="100%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#CCCCCC" class="normaltextfield">
 
		<tr>
            <td height="29"> <div align="right"><span class="pequeno"><strong><font color="#FF0000">*</font></strong></span> 
                      Categoria:</div></td>
 
				<td><select name="categoria" id="categoria" onchange="cambia_idcat()" style="width:316px;">
                <option value="">CATEGORIA</option>
                 <?php while($tip=mysql_fetch_array($result1)){?>
                <option value="<?php echo $tip['id_categoria'];?>"><?php echo $tip['categoria'];?></option>
                 <?php } ?>
                </select><input type="text" id="idcat3" value=""></td>
 
 
				<td height="29"> <div align="right"><span class="pequeno"><strong><font color="#FF0000">*</font></strong></span> 
                      Linea:</div></td>
                  <td><select name="linea" id="linea" onchange="cambia_idlin()"  style="width:316px;">
                      <option value="">LINEA</option>
                      <?php while($tip=mysql_fetch_array($result2)){?>
                      <option value="<?php echo $tip['id_linea'];?>"><?php echo $tip['linea'];?></option>
                      <?php } ?>
                    </select><input type="text" name="id_linea" value="<?php echo $tip['id_linea'];?>" /></td>
        </tr>
 
 
                <tr>
                  <td height="29">&nbsp;</td>
                  <td>&nbsp;</td><td colspan="2"></td>
        </tr>
 
	</table>
	<table width="54%" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr><td></td><td></td></tr>
				<tr>
                  <td width="48%"><div align="right">
                      <input name="Agregar" type="submit" id="send" value="Agregar">
                    </div></td>
                  <td width="52%"><input name="cancel" type="reset" id="cancel" onClick="MM_goToURL('parent','index.php');return document.MM_returnValue" value="Cancelar"></td>
                </tr>
              </table>
              <table width="48%" border="0" align="center" cellpadding="0" cellspacing="0">  <tr><td></td><td></td></tr>
                <tr>
                  <td width="62%"><div align="right"><span class="pequeno">Los
                      campos con</span> <span class="titulorojo"><strong><font color="#FF0000">*</font></strong></span> 
                      <span class="pequeno">son obligatorios</span></div></td>
                  <td width="38%">&nbsp;</td>
                </tr>
              </table>
<?php  if(isset($_REQUESTT['Agregar'])){
$agregar=$_REQUESTT['Agregar'];
 
		$query="insert into categ_linea (id_categoria,id_linea) values ('$idcategoria','$idlinea')";
		$result=mysql_query($query);
 
		if($result){
		echo "<script>alert('Registro Insertado Con Exito!');window.location='categlinea_list.php';</script>";
		}
		else {
		echo "<script>alert('Ha ocurrido un error consulte con el Encargado');window.location='categlinea_list.php';</script>";
		}
			}
		?>
 
                   </form>
     </tr>
              </table>
			  </td>
			   </table>
    </body>
</html>

Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

mostrar datos de dos tablas con select y registrar en otra la relacion

Publicado por xve (6935 intervenciones) el 21/06/2014 18:09:51
Hola Moreira, cuesta un poco de entender tu código... exactamente que quieres hacer? seleccionar una tabla y que se copie en otra tabla?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

mostrar datos de dos tablas con select y registrar en otra la relacion

Publicado por moreira (3 intervenciones) el 22/06/2014 00:37:34
Si estoy relacionando la tabla categorías con la tabla líneas en otra tabla denominada categlinea

por la tabla categorías tengo un select y por la tabla líneas tengo otro selec donde muestro las opciones a elegir. hasta ahí todo bien.

pero el problema es cuando selecciono de la lista las opciones, necesito enviar el id_categoria y el id_linea a la tabla categlinea y no me funciona como enviar los Ids de cada tabla.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar