Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/03/2009, 10:48
exorton
 
Fecha de Ingreso: marzo-2009
Mensajes: 41
Antigüedad: 15 años, 1 mes
Puntos: 1
me da query vacio, siendo que existe

Tengo un formulario que ingresa los valores en POST, con el formulario pretendo obtener restricciones para una busqueda. Los datos son de personas, RUT, nombre, fecha nacimiento (fech), rango en la empresa (compuesto por 3 pares de nuemeros que los llamo rang1, rang2, rang3)

por ahora estoy pidiendo que pueda descriminarse por cualquier valor que se entregue en el formulario el codigo que tengo es.

<?PHP
//cabecera de la pagina habre el html y body etc..
include(cabecera);
//coneccion a la db
include(conexion);

//quita puntos y - si se anotan en el rut
$ra=strtoupper(ereg_replace('\.|,|-','',$_POST[rut]));

//contador que uso para ver si hay mas de un dato agregado en el formulario
$restr="0";

//ordena la fecha para mysql la fecha se ingresa dia-mes-año
$fecha = explode("-",$_POST[fech]);
$fechaMySQL1=$fecha[2]."-".$fecha[1]."-".$fecha[0];


//aqui defino la restriccion o restricciones para la busqueda. guardandolo en $brut1
//si no esta vacio y es el primero agregara al quiery WHERE y no AND
if(!empty($_POST['rut'])) {
$brut1="WHERE 'rut' = '$ra'";
$restr=$restr+1;
}
//si existe agrega si es el priemero Where o si es segunda o mas restriccion AND
if(!empty($_POST['nombre'])) {
if ($restr>=1) {
$brut1= $brut1." AND 'nombre' = ".$_POST['nombre'];
} else {
$brut1= "WHERE 'nombre' = ".$_POST['nombre'];}
$restr=$restr+1;
}

if(!empty($_POST['fech'])) {
if ($restr>=1) {
$brut1= $brut1." AND 'fech' <= '$fechaMySQL1'";
} else {
$brut1= "WHERE 'fech' <= '$fechaMySQL1'";}
$restr=$restr+1;
}

if(!empty($_POST['rang1'])) {
if ($restr>=1) {
$brut1= $brut1." AND 'rang1' = ".$_POST['rang1'];
} else {
$brut1= "WHERE 'rang1' = ".$_POST['rang1'];}
$restr=$restr+1;
}

if(!empty($_POST['rang2'])) {
if ($restr>=1) {
$brut1= $brut1." AND 'rang2' = ".$_POST['rang2'];
} else {
$brut1= "WHERE 'rang2' = ".$_POST['rang2'];}
$restr=$restr+1;
}

if(!empty($_POST['rang3'])) {
if ($restr>=1) {
$brut1= $brut1." AND 'rang3' = ".$_POST['rang3'];
} else {
$brut1= "WHERE 'rang3' = ".$_POST['rang3'];}
$restr=$restr+1;
}

//aqui termina la restriccion
$query="SELECT * FROM pruebafac $brut1 ORDER BY fech ASC";
$resulta=mysql_query($query) or die ($query .mysql_error()."" ) ;
?>
<table align="center" border="1">
<colgroup>
<col width=220>
<col >
<col >
<col >
<col >
<col >
</colgroup>
<tr class="encabezado">
<colgroup>
<col width=220> <col > <col > <col > <col > <col > <col >
</colgroup>
<tr>
<th>Nombre</th> <th>Rut</th> <th>Nacimiento</th> <th>Rango 1</th> <th>Rango 2</th> <th>Rango 1</th> >
</tr>
<?php
while ($row=mysql_fetch_array($resulta))
{
echo "<td><center>".$row["nombre"]."</center></td>";
echo "<td><center>".$row["rut"]."</center></td>";
echo "<td><center>".$row["fech"]."</center></td>";
echo "<td><center>".$row["rang1"]."</center></td>";
echo "<td><center>".$row["rang2"]."</center></td>";
echo "<td><center>".$row["rang3"]."</center></td>";

mysql_close($con);
?>

y no me da resultados me da solo los titulos de la tabla y la tabla sin ningun datos.

he puesto echo print_r($row) y me da valor 1 y mysql_num_rows($resulta) me da valor 0 y cuando hago que me muestre $query me muestra el dialogo para la consulta bien lo copio y pego en el mysql y si me entrega resultados. el $resulta me da Resource id #5.

Nose que le pasa no se como hacer un debugger en el paso que esta en $row