Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/01/2010, 16:06
ex197
 
Fecha de Ingreso: enero-2010
Mensajes: 2
Antigüedad: 14 años, 3 meses
Puntos: 0
Pregunta Resultado erroneo de consulta doble a MySQL

Hola... soy nuevo en PHP, JavaScript y consultas a MySQL y tengo el siguiente
problema: "Cuando ingreso 2 campos / codigós vía <input necesito que aparezcan al lado su nombre asociado que está en 2 tablas de MySQL, las cuales corresponden a COMUNAS y ESTABLECIMIENTOS", el asunto resulta, pero el problema es que cuando aparece uno de ellos se borra el otro y viceversa, seguramente debe ser a causa de mala estructuración de los forms, o algo que sobra o falta, bueno les adjunto el script respectivo en PHP a ver si por favor me pueden ayudar en forma URGENTEEEEEE !!. Entiendo que esto puede resolverse quizás mejor con AJAX pero he estado buscando durante muchos días sin éxito.

Muchas Gracias!
<html>
<head>
</head>
<body bgcolor="#FFFFF7" TEXT="#000066" LINK="#000066" VLINK="#800080">
<title>Comuna</title>

<form name="forma1" action="<? print $_SERVER['PHP_SELF']?>" enctype="multipart/form-data" method="post">

<table border=0>
<tr>
<td colspan=2 align="center" valign="top" class="FormText">
<font size="2" color="#000066"><b>COMUNA</b></font>
</td>
</tr>
<tr>
<?php
$host="localhost"; $username="root"; $password="";
mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db('egrhosp_db') or die(mysql_error());
?>

<form name="comuna" action="<? print $_SERVER['PHP_SELF']?>" enctype="multipart/form-data" method="post">
<td>
<input type="text" name="IdC" size="5" maxlength=5 value="<?php if (isset($_POST['IdC'])) echo $_POST['IdC'];?>"

onChange='this.form.submit()'>
</td>
<?php
extract($_POST);
?>
<script language="JavaScript">
/* por ver donde y como va si corresponde: http://www.forosdelweb.com/f18/visualizar-input-text-respuesta-ajax-713008/
document.getElementById("IdC").value=xmlhttp.respo nseText;
document.getElementById("NComuna").value=xmlhttp.r esponseText;
</script>
<?php
# echo "IdC =".$IdC."<br>";
# echo "IdE =".$IdE."<br>";
if( isset($_POST['IdC']) ) {
$IdC = $_POST[IdC];
$sql ="SELECT * FROM comuna where IdComuna like \"$IdC\"" or die(mysql_error());
$query = mysql_query($sql);
while ( $res=@mysql_fetch_array($query) ) {
echo "<td>$res[NComuna]</td>";
}
}
?>
</td>
</tr>
</table>
</form>
<form name="forma2" action="<? print $_SERVER['PHP_SELF']?>" enctype="multipart/form-data" method="post">

<table border=0>
<tr>
<td colspan=2 align="center" valign="top" class="FormText">
<font size="2" color="#000066"><b>ESTABLECIMIENTO</b></font>
</td>
</tr>
<tr>
<?php
$host="localhost"; $username="root"; $password="";
mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db('egrhosp_db') or die(mysql_error());
?>
<td>
<input type="text" name="IdE" size="6" maxlength=6 value="<?php echo (isset($_POST['IdE']))?$_POST['IdE']:'';

?>" onChange='this.form.submit()'>
</td>
<?php
if( isset($_POST['IdE']) ) {
$IdE = $_POST[IdE];
$sql ="SELECT * FROM establecimiento where IdEstablecimiento like \"$IdE\"" or die(mysql_error());
$query = mysql_query($sql);
while ( $res=@mysql_fetch_array($query) ) {
echo "<td>$res[NEstablecimiento]</td>";
}
}
?>
</td>
</tr>
</table>
</form>
</form>
</center>
</body>
</html>