PHP - Como recuperar datos mediante un select

 
Vista:
Imágen de perfil de Angel

Como recuperar datos mediante un select

Publicado por Angel (20 intervenciones) el 26/09/2015 06:43:42
hola a todos tengo un pequeño problema estoy tratando de realizar una aplicación para buscar y editar registros de dos tablas diferentes
Este es mi codigo de busqueda el cual envia el resultado de busqueda a otra pagina llamada mod_nacer
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
138
139
140
141
142
<?php
$colname_rsvoluntarios = "-1";
if (isset($_POST['txt_caja'])) {
  $colname_rsvoluntarios = $_POST['txt_caja'];
}
error_reporting(E_ALL ^ E_WARNING ^ E_NOTICE);
 
mysql_select_db($db, $cn);
if($_POST['seleccion']==1)
{
$query_rsvoluntarios = sprintf("SELECT nacionalidad.ID_NACIONALIDAD, nacionalidad.NOMBRE_NACIONALIDAD, nacionalidad.CANTIDAD,
  nivel_educacion.ID_EDUCACION, nivel_educacion.NIVEL, nivel_educacion.ESTADO_EDUCACION, nivel_educacion.CANTIDAD_EDUCANDOS
FROM nacionalidad
INNER JOIN edunac ON edunac.ID_NACIONALIDAD = nacionalidad.ID_NACIONALIDAD
INNER JOIN nivel_educacion ON nivel_educacion.ID_EDUCACION = edunac.ID_EDUCACION WHERE NOMBRE_NACIONALIDAD LIKE %s ORDER BY NOMBRE_NACIONALIDAD ASC", GetSQLValueString("%" . $colname_rsvoluntarios . "%", "text"));
 
 
}
else {
 
$query_rsvoluntarios = sprintf("SELECT nacionalidad.ID_NACIONALIDAD, nacionalidad.NOMBRE_NACIONALIDAD, nacionalidad.CANTIDAD, nivel_educacion.ID_EDUCACION, nivel_educacion.NIVEL, nivel_educacion.ESTADO_EDUCACION, nivel_educacion.CANTIDAD_EDUCANDOS
FROM nacionalidad
INNER JOIN edunac ON edunac.ID_NACIONALIDAD = nacionalidad.ID_NACIONALIDAD
INNER JOIN nivel_educacion ON nivel_educacion.ID_EDUCACION = edunac.ID_EDUCACION WHERE NIVEL LIKE %s ORDER BY NOMBRE_NACIONALIDAD ASC ", GetSQLValueString("%" . $colname_rsvoluntarios . "%", "text"));
}
 
$rsvoluntarios = mysql_query($query_rsvoluntarios, $cn) or die(mysql_error());
$row_rsvoluntarios = mysql_fetch_assoc($rsvoluntarios);
$totalRows_rsvoluntarios = mysql_num_rows($rsvoluntarios);
 
 
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<link href="../css/estilos4.css" rel="stylesheet" type="text/css" />
<script src="../SpryAssets/SpryEffects.js" type="text/javascript"></script>
<script type="text/javascript">
 
function MM_effectGrowShrink(targetElement, duration, from, to, toggle, referHeight, growFromCenter)
{
  Spry.Effect.DoGrow(targetElement, {duration: duration, from: from, to: to, toggle: toggle, referHeight: referHeight, growCenter: growFromCenter});
}
 
</script>
</head>
 
<body onload="MM_effectGrowShrink('form1', 1000, '0%', '100%', false, false, true)">
<form id="form1" name="form1" method="post" action="">
  <table width="650" border="0" align="center" class="tabla">
    <tr>
      <td colspan="2" class="titulo">Busqueda y Modificacion de Nacionalidad Educacion y Servicio Basico </td>
    </tr>
    <tr>
      <td width=""><table width="200">
        <tr>
          <td width="70"><label>
            <input type="radio" name="seleccion" value="1" id="seleccion_0" />
            Nacionalidad</label></td>
        </tr>
        <tr>
          <td><label>
            <input type="radio" name="seleccion" value="2" id="seleccion_1" />
            Nivel Educacion</label></td>
        </tr>
      </table></td>
      <td width="50"><label>
        <input name="txt_caja" type="text" id="txt_caja" placeholder="Por favor active la busqueda individual por Nacionalidad o Nivel Educacion " size="60" maxlength="50" />
      </label></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><label>
        <input name="btn_buscar" type="submit" class="botones" id="btn_buscar" value="Buscar" />
      </label></td>
 
    </tr>
 
    <tr><td><label> Atencion!! para modificar de un click sobre el registro...
        </label></td></tr>
  </table>
  <br></br>
  <table width="900" border="0" align="center" class="tabla">
    <tr>
      <td colspan="6" class="titulo">Localizacion del Sector</td>
    </tr>
    <tr>
     <th width="61">Nacionalidad</td>
     <th width="157">Cantidad Nacionalidad</th>
     <th width="221">Nivel Educacion</th>
     <th width="157">Estado</th>
     <th width="221">Cantidad Educandos</th>
 
   </tr>
    <?php
  $num_fila = 0;
  do
  {
 if ($num_fila%2==0)
    {
  ?>
      <tr class="fila1" onclick="location.href='../MDR/mod_naceser.php?valor=<?php echo  $row_rsvoluntarios['ID_NACIONALIDAD'];?>'"> // este es la parte donde envio hacia la otra pagina
        <td><?php echo $row_rsvoluntarios['NOMBRE_NACIONALIDAD']; ?></td>
        <td><?php echo $row_rsvoluntarios['CANTIDAD']; ?></td>
        <td><?php echo $row_rsvoluntarios['NIVEL']; ?></td>
        <td><?php echo $row_rsvoluntarios['ESTADO_EDUCACION']; ?></td>
        <td><?php echo $row_rsvoluntarios['CANTIDAD_EDUCANDOS']; ?></td>
 
 
 
 
 
      </tr>
      <?php
    }
    else
    {
  ?>
      <tr  class="fila2" onclick="location.href='../MDR/mod_naceser.php?valor=<?php echo $row_rsvoluntarios['ID_EDUCACION'];?>'">
         <td><?php echo $row_rsvoluntarios['NOMBRE_NACIONALIDAD']; ?></td>
        <td><?php echo $row_rsvoluntarios['CANTIDAD']; ?></td>
        <td><?php echo $row_rsvoluntarios['NIVEL']; ?></td>
        <td><?php echo $row_rsvoluntarios['ESTADO_EDUCACION']; ?></td>
        <td><?php echo $row_rsvoluntarios['CANTIDAD_EDUCANDOS']; ?></td>
 
      </tr>
      <?php
 
  }
   $num_fila++;
    } while ($row_rsvoluntarios = mysql_fetch_assoc($rsvoluntarios)); ?>
  </table>
  <p>&nbsp;</p>
</form>
<br />
</body>
</html>
<?php
mysql_free_result($rsvoluntarios);
?>


la búsqueda me la realiza muy bien o que no consigo es recuperar los en un select para poder modificar su informacion este es el codigo para modificar

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
<?php
$colname_rsvoluntario = "-1";
if (isset($_GET['valor'])) {
  $colname_rsvoluntario = $_GET['valor'];
}
mysql_select_db($db, $cn);
$query_rsvoluntario = sprintf("SELECT * from nacionalidad WHERE ID_NACIONALIDAD =%s" , GetSQLValueString($colname_rsvoluntario, "int"));
$rsvoluntario = mysql_query($query_rsvoluntario, $cn) or die(mysql_error());
$row_rsvoluntario = mysql_fetch_assoc($rsvoluntario);
$totalRows_rsvoluntario = mysql_num_rows($rsvoluntario);
 
 
 
mysql_select_db($db, $cn);
$query_rsespecie = sprintf("SELECT * from  nivel_educacion WHERE ID_EDUCACION LIKE %s" , GetSQLValueString($colname_rsvoluntario, "int"));
$rsespecie = mysql_query($query_rsespecie, $cn) or die(mysql_error());
$row_rsespecie = mysql_fetch_assoc($rsespecie);
$totalRows_rsespecie = mysql_num_rows($rsespecie);
 
 
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</script>
</head>
<body onload="ocultar('<?php echo $bandera;?>');MM_effectGrowShrink('form1', 1000, '0%', '100%', false, false, true)">
<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1" onsubmit="MM_validateForm('txt_cedula','','NisNum','txt_email','','NisEmail','txt_telefono','','NisNum');return document.MM_returnValue">
  <table width="500" border="0" align="center" class="tabla">
    <tr>
      <td colspan="2" class="titulo">Modificar Sector<span id="sprytextfield8">
        <label>
          <input name="txt_cod_voluntario" type="hidden" id="txt_cod_voluntario" value="<?php echo $_POST['valor'];?>"/>
        </label>
      <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
    </tr>
      <th width="66">Nacionalidad </th>
      <td width="313"><span id="sprytextfield1">
      <label>
        <input name="txt_Nacionalidad" type="text" class="cajas" id="txt_Nacionalidad"  value="<?php echo $row_rsvoluntario['NOMBRE_NACIONALIDAD']; ?>" size="50" maxlength="80" onkeypress="return letras(event)"/>
      </label>
      <span class="textfieldRequiredMsg">*</span><span class="textfieldMaxCharsMsg">Se ha superado el número máximo de caracteres.</span></span></td>
    </tr>
    <td></td>
    <tr>
      <th width="66">Cantidad</th>
      <td width="313"><span id="sprytextfield2">
      <label>
        <input name="txt_Cantidad" type="text" class="cajas" id="txt_Cantidad" value="<?php echo $row_rsvoluntario['CANTIDAD']; ?>" size="50" maxlength="80" onkeypress="return letras(event)"/>
      </label>
      <span class="textfieldRequiredMsg">*</span><span class="textfieldMaxCharsMsg">Se ha superado el número máximo de caracteres.</span></span></td>
    </tr>
   <td></td>
       <tr>
      <td>Pais</td>
      <td><span id="spryselect1">
        <label>
          <select name="txt_pais" class="cajas" id="txt_pais">
            <option value="Primaria" <?php if (!(strcmp("Primaria", $row_rsvoluntario['NIVEL']))) {echo "selected=\"selected\"";} ?>>Primaria</option>
            <option value="Secundaria" <?php if (!(strcmp("Secundaria", $row_rsvoluntario['NIVEL']))) {echo "selected=\"selected\"";} ?>>Secundaria</option>
            <option value="Superior" <?php if (!(strcmp("Superior", $row_rsvoluntario['NIVEL']))) {echo "selected=\"selected\"";} ?>>Superior</option>
            <option value="Ninguna" <?php if (!(strcmp("Ninguna", $row_rsvoluntario['NIVEL']))) {echo "selected=\"selected\"";} ?>>Ninguna</option>
            </select>
        </label>
      <span class="selectInvalidMsg">Seleccione un elemento válido.</span><span class="selectRequiredMsg">*</span></span></td>
    </tr>
    <td></td>
      <tr>
      <th>Beneficiarios</th>
      <td><span id="spryselect2">
        <label>
          <select  style="width: 200px" name="Cbo_Estado_Educacion"  class="cajas" id="Cbo_Estado_Educacion">
          <option value="Cursando" <?php if (!(strcmp("Cursando", $row_rsvoluntario['ESTADO_EDUCACION']))) {echo "selected=\"selected\"";} ?>>Cursando</option>
          <option value="Finalizado" <?php if (!(strcmp("Finalizado", $row_rsvoluntario['ESTADO_EDUCACION']))) {echo "selected=\"selected\"";} ?>>Finalizado</option>
          <option value="Inconcluso" <?php if (!(strcmp("Inconcluso", $row_rsvoluntario['ESTADO_EDUCACION']))) {echo "selected=\"selected\"";} ?>>Inconcluso</option>
          </select>
        </label>
      <span class="selectInvalidMsg">Seleccione un elemento válido.</span><span class="selectRequiredMsg">*</span></span></td>
    </tr>
 
    <tr>
       <th width="66">Problema</th>
      <td width="313"><span id="sprytextfield3">
      <label>
        <input name="Cbo_Cantidad_Educandos" type="text" class="cajas" id="Cbo_Cantidad_Educandos" value="<?php echo $row_rsespecie['CANTIDAD_EDUCANDOS']; ?>" size="50" maxlength="80" />
      </label>
      <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">*</span><span class="textfieldMaxCharsMsg">Se ha superado el número máximo de caracteres.</span></span></td>
    </tr>
<td></td>
    <tr>
      <td colspan="2" align="center"><label>
        <input name="btn_guardar" type="submit" class="botones" id="btn_guardar" onclick="MM_validateForm('txt_Provincia','','R', 'txt_Canton','','R', 'txt_Parroquia','','R', 'txt_Sector','','R', 'Cbo_Localizacion','','R','Cbo_Beneficiarios','','R', 'txt_Problema','','R',  'txt_Causas','','R', 'txt_Efectos','','R');return document.MM_returnValue" value="Actualizar" />
      </label></td>
      </label></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1" />
</form>
 
</body>
</html>
<?php

la parte del select 1 y select 2 es la que me da problemas por que no logro recuperar los datos ingresados anteriormente,
no se si me hise entender espero que si pero en otras palabras lo que quiero hacer es la opcion tipica de los paises (Argentina, Bolivia, Ecuador,Estados Unidos ect) si seleccione un pais y la ingrese ali bse de datos me recupere el mismo pais a traves del select,,
espero que me puedan ayudar o si tienen algun otro codigo o idea pra hacer lo que quiere se los agradeseria muchisimo
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