Código Javascript :
<script language="javascript" type="text/javascript">
var READY_STATE_COMPLETE=4;
var peticion_http = null;
function inicializa_xhr() {
if(window.XMLHttpRequest) {
return new XMLHttpRequest();
}
else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function crea_query_string() {
var cl = document.getElementById("clave");
var cr = document.getElementById("criterio_str");
return "clave=" + encodeURIComponent(cl.value) +
"&criterio_str=" + encodeURIComponent(cr.value) +
"&nocache=" + Math.random();
}
function busca() {
peticion_http = inicializa_xhr();
if(peticion_http) {
peticion_http.onreadystatechange = procesaRespuesta;
peticion_http.open("POST", "/usuario_ver_omega.php", true);
peticion_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var query_string = crea_query_string();
peticion_http.send(query_string);
}
}
function procesaRespuesta() {
if(peticion_http.readyState == READY_STATE_COMPLETE) {
if(peticion_http.status == 200) {
document.getElementById("resultados").innerHTML = peticion_http.responseText;
}
}
}
</script>
Código HTML :
<table width='100%' border='0' align='center' cellpadding='0' cellspacing='0'> <tr> <td> <table width="100%" align="center" cellpadding="0" cellspacing="0"> <tr> <td class="left"> </td> <td width="15" class="center"><img src="imagenes/bullet_title.gif"></td> <td align="left" class="center"><span class="Estilo3">Modulo de Usuarios.</span></td> <td class="right"> </td> </tr> </table> </td> </tr> <tr> <td align="center" style="padding-top:10px"> <form action="javascript:busca();" method="post" name="buscador" id="buscador" style="border:none"> <input type="text" name="clave" id="clave" value="Ingrese texto a buscar" onFocus="if(this.value=='Ingrese texto a buscar')this.value='';" style="width:30%; margin-right:20px"> <input type="submit" name="submit" id="submit" value="Buscar"> <br> <br/> <label>Seleccione un criterio de Busqueda :<br/> <input name="criterio_str" type="radio" value="Nombres" id="GrupoOpciones1_0" checked> Nombres</label> <label> <input name="criterio_str" type="radio" value="Apellidos" id="GrupoOpciones1_1"> Apellidos</label> <label> <input name="criterio_str" type="radio" value="Cargo" id="GrupoOpciones1_2"> Cargo</label> <label> <input name="criterio_str" type="radio" value="Area" id="GrupoOpciones1_3"> Area</label> <label> <input name="criterio_str" type="radio" value="Nacionalidad" id="GrupoOpciones1_4"> Nacionalidad</label> </form> </td> </tr> <tr> <td> <div id="resultados"> </div> </body> </html>
Esa es la primera pagina la del formulario y esta es la que muestra
Código PHP :
<?php
require_once('Connections/conexion.php');
session_start();
if (isset($_POST[criterio_str]) && isset($_POST[clave])){
$criterio = $_POST[criterio_str];
$clave = $_POST[clave];
echo "Criterio de busqueda : $criterio<br/>";echo "Clave de busqueda : $clave<br/>";
switch ($criterio) {
case "Nombres" :
$busqueda = "pre_nombre LIKE '%".$clave."%' OR mas_nombre LIKE '%".$clave."%'";
break;
case "Apellidos" :
$busqueda = "ap_paterno LIKE '%".$clave."%' OR ap_materno LIKE '%".$clave."%'";
break;
case "Cargo":
$busqueda = "cargo_ingreso LIKE '%".$clave."%'";
break;
case "Area":
$busqueda = "area_ LIKE '%".$clave."%'";
break;
case "Nacionalidad":
$busqueda = "nacionalidad LIKE '%".$clave."%'";
break;
default :
$busqueda = "ap_paterno LIKE '%".$clave."%' OR ap_materno LIKE '%".$clave."%' OR ap_paterno LIKE '%".$clave."%' OR ap_materno LIKE '%".$clave."%' OR cargo_ingreso LIKE '%".$clave."%' OR area_ LIKE '%".$clave."%' OR nacionalidad LIKE '%".$clave."%'";
break;
}
$query_Usuarios = "SELECT * FROM usuarios_ WHERE $busqueda";
$Usuarios = mysql_query($query_Usuarios) or die(mysql_error());
$row_Usuarios = mysql_fetch_assoc($Usuarios);
$totalRows_Usuarios = mysql_num_rows($Usuarios);
}
?>
<link href="estilos.css" rel="stylesheet" type="text/css">
<body>
<? if (isset($criterio) && isset($clave)) { ?>
<table width='100%' border='0' align='center' cellpadding='0' cellspacing='10'>
<tr>
<td colspan="2">Resultados de Buscar <strong>"<?php echo $clave; ?>"</strong> por <strong><?php echo $criterio."</strong> : <strong>".$totalRows_Usuarios."</strong> registros coincidientes";?></strong></td>
</tr>
<?php if ($totalRows_Usuarios > 0) {?>
<tr>
<td colspan='2'>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="5">
<tr>
<td><strong>APELLIDOS,
Nombres</strong></td>
<td><strong>Area</strong></td>
<td><strong>Cargo</strong></td>
<td><strong>Nacionalidad</strong></td>
<td align="center"><strong>Ver</strong></td>
</tr>
<?php
do {
?>
<tr>
<td>
<?php echo strtoupper($row_Usuarios['ap_paterno']." ".$row_Usuarios['ap_materno']).", ".ucwords(strtolower($row_Usuarios['pre_nombre']." ".$row_Usuarios['mas_nombre'])); ?> </td>
<td><?php echo $row_Usuarios['area_'];?></td>
<td><?php echo $row_Usuarios['cargo_ingreso'];?></td>
<td><?php echo $row_Usuarios['nacionalidad'];?></td>
<td width="75px" align="center">
<a href='javascript:showing("destino","ver_user.php?user=<? echo $row_Usuarios['Id'] ?>")'>Ver Ficha</a></td>
</tr>
<?php
} while ($row_Usuarios = mysql_fetch_assoc($Usuarios));
$rows = mysql_num_rows($Usuarios);
if($rows > 0) {
mysql_data_seek($Usuarios, 0);
$row_Usuarios = mysql_fetch_assoc($Usuarios);
}
?>
</table>
</td>
</tr>
<?php } else {?>
<tr>
<td colspan="2">
<strong>La busqueda no reporta resultados</strong></td>
</tr>
<?php } ?>
</table>
<? }; ?>
</body>
</html>
<?php
if (isset($_POST[criterio_str]) && isset($_POST[$clave])){
mysql_free_result($Usuarios);
};
?>
Existe algun error en mi codigo? pq cuando le doy al boton BUSCAR (submit) la pagina no hace nada de nada.
