PHP - problemas para mostrar u ocultar informacion con jquery

 
Vista:
sin imagen de perfil

problemas para mostrar u ocultar informacion con jquery

Publicado por martin (24 intervenciones) el 25/03/2018 17:52:55
HOLA AMIGOS DEL FORO MI CONSULTA ES LA SIGUIENTE

TENGO DOS TABLAS LA PRIMERA DEPARTAMENTOS Y LA SEGUNDA CIUDADES CON LA SIGUIENTE ESTRUCTURA

//TABLA DEPARTAMENTOS
ID_DEPARTAMENTO
DESCRIPCION

//TABLA CIUDADES CON UNA CLAVE FORANEA QUE APUNTA A DEPARTAMENTOS
ID_CIUDAD
ID_DEPARTAMENTO
DESCRIPCION

AMBAS TABLAS CON LA SIGUIENTE INFORMACION
//TABLA DEPARTAMENTOS
ID_DEPARTAMENTO DESCRIPCION
1 ASUNCION
2 ALTO PARANA

//TABLA CIUDADES
//CIUDADES DE ASUNCION
ID_CIUDAD ID_DEPARTAMENTO DESCRIPCION
1 1 LAMBARE
1 1 FERNANDO DE LA MORA
1 1 CAPIATA

//CIUDADES DE ALTO PARANA
ID_CIUDAD ID_DEPARTAMENTO DESCRIPCION
1 2 MINGA GUAZU
1 2 PRESIDENTE FRANCO
1 2 HERNANDARIAS

AHORA TENGO EL SIGUIENTE CODIGO EN DONDE AL HACER CLICK EN EL ENLACE SOLO ME FUNCIONA PARA EL PRIMER DEPARTAMENTO Y PARA LOS RESTANTES NO FUNCIONA Y
NECESITO QUE FUNCIONE PARA TODOS LOS DEPARTAMENTOS PERO TAMBIEN NECESITO RECUPERAR LA CLAVE PRIMARIA DE LA TABLA DEPARTAMENTOS, ENTONCES AL HACER
CLICK MEDIANTE LA CLAVE DEBERIA RECUPERAR TODAS LAS CIUDADES DE CADA UNO DE LOS DEPARTAMENTOS EJEMPLO AL HACER CLICK EN ASUNCION DEBERIA MOSTRAR
TODAS LAS CIUDADES DE ASUNCION, AL HACER CLICK EN ALTO PARANA DEBERIA TRAER TODAS LA CIUDADES DE ALTO PARANA.

ASI AL HACER CLICK EN EL DEPARTAMENTO ME DEBRIA MOSTRAR TODAS LAS CIUDADES QUE FORMAN PARTE DE ESE DEPARTAMENTO

ALGUIEN SABE COMO HACER ESTO? POR FAVOR


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
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
 
/* FUNCION */
<script>
$(document).ready(function()
{
 
 $('#expandir').on('click',function(){
 $('#respuesta1').toggle();
 });
 
});
</script>
 
 
printf("<table border='0' >");
printf("<tr> <td> CODIGO </td> <td>DESCRIPCION</td> </tr>");
 
//recupero todos los departamentos de la tabla
$resul = mysql_query("SELECT * FROM deptos WHERE estado='activo' ORDER BY descripcion");
 
while ( $recuperar = mysql_fetch_array($resul) )
{
   printf("<tr>");
 
   // IMPRIMO CLAVE PRIMARIA DE LA TABLA DEPARTAMENTOS Y EL LINCK DONDE DEBERIA 
   MOSTRAR U OCULTAR LAS CIUDADES
   printf("<td class='cuerpo'> <a href='#' id='expandir'><b>+</b></a> %s</td>",$recuperar['id_departamento']);
 
    printf("<div id='respuesta1' style='display:none'>");
 
 // ACA NECESITO RECUPERAR EL ID DEL DEPARTAMENTO PARA RECUPERAR TODAS LAS CIUDADES
 // LA CLAVE NECESITO RECUPERAR DE CADA DEPARTAMENTO $id_departamento
 // EJEMPLO 
 // $ciudades = mysql_query("SELECT * FROM ciuadades WHERE id_departamento='$id_departamento'");
 
     printf("Respuesta...");
     printf("</div>");
 
      // IMPRIMO TODOS LOS DEPARTAMENTOS
      printf("<td class='cuerpo'> %s </td>",strtoupper($recuperar['descripcion']));
 
      printf("</tr>");
 
}
 
printf("<tr> <td colspan='2'> </td></tr>");
printf("</table>");
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

problemas para mostrar u ocultar informacion con jquery

Publicado por Yamil Bracho (24 intervenciones) el 25/03/2018 18:09:30
Es mas facil y optimo que hagas una sola consulta y traigas toda la informacion. Es decir, haces

SELECT deptos.id_departamento, deptos.descripcion,
ciudades.id_ciudad, ciudades.descripcion
FROM deptos
INNER JOIN ciudades ON ciudades.id_departamento = deptos.id_departamento
ORDER BY deptos.descripcion, ciudades.descripcion

Y luego recorres ese resultado
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

problemas para mostrar u ocultar informacion con jquery

Publicado por martin (24 intervenciones) el 25/03/2018 18:57:53
hola yamil gracias por la colaboración, pero en mi caso no me sirve, ya que inicialmente debo desplegar la lista de departamentos, luego al seleccionar el departamento debo mostrar las ciudades de ese departamento.

Por que la intención es que se seleccione el departamento al azar y luego despliegue todas sus ciudades y no que me despliegue todos los departamentos juntamente con la ciudades.
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

problemas para mostrar u ocultar informacion con jquery

Publicado por Yamil Bracho (24 intervenciones) el 25/03/2018 19:11:20
Ok.
En ese caso tendrias que hacer un script en PHP que reciba el departamento y te busque las ciudades. Puedes hacer eso con Javascript, JQuery ajax (post o get) y por supuesto PHP
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

problemas para mostrar u ocultar informacion con jquery

Publicado por martin (24 intervenciones) el 25/03/2018 20:29:31
si gracias lamentablemente no lo se hacer aguardo que alguien me ayude
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