Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/05/2011, 12:04
nandosoftware
 
Fecha de Ingreso: mayo-2011
Ubicación: españa
Mensajes: 10
Antigüedad: 13 años
Puntos: 0
Error en consulta

Hola!
Estoy creando una BD para crear un cambio de turno con php y sql dentro del cual hay un apartado para realizar busqueda por fecha de los registros introducidos en la BD y mostrados en el mismo formulario donde se insertan los datos de cambio de turno,pero el problema es que cuando le doy al boton de buqueda,no me devuelve los resultados.pego el codigo por si alguien me puede ayudar a ver el fallo.Gracias!!
Codigo:
<?php
require_once('F_design.php');
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;

// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}

$MM_restrictGoTo = "noautorizado.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}

//Cogemos los datos
$FILAS_POR_PAGINA = 1;
$pagina = (isset($_GET["pagina"]))?$_GET["pagina"]:0;
if (isset($_GET["fecha_inicio"]))
{
$trozos = explode("-",$_GET["fecha_inicio"]);
$fecha_inicio = $trozos[2] . "-" . $trozos[1] . "-" . $trozos[0];
$fecha_inicio_str = $_GET["fecha_inicio"];
}
else
{
$fecha_inicio = "2010-01-01";
$fecha_inicio_str = "01-01-2010";
}

if (isset($_GET["fecha_fin"]))
{
$trozos = explode("-",$_GET["fecha_fin"]);
$fecha_fin = $trozos[2] . "-" . $trozos[1] . "-" . $trozos[0];
$fecha_fin_str = $_GET["fecha_fin"];
}
else
{
$fecha_fin = date("Y-m-d");
$fecha_fin_str = date("Y-m-d");
}

if (isset($_POST)) {
mysql_select_db($database_turno, $turno);

$offset = ($FILAS_POR_PAGINA*$pagina);
$query=sprintf("SELECT * FROM diario WHERE FECHA>='%s' AND FECHA<='%s' LIMIT $FILAS_POR_PAGINA OFFSET $offset",
get_magic_quotes_gpc() ? $fecha_inicio: addslashes($fecha_inicio), get_magic_quotes_gpc() ? $fecha_fin : addslashes($fecha_fin));

$result = mysql_query($query, $turno) or die(mysql_error());
$query=sprintf("SELECT * FROM diario WHERE FECHA>='%s' AND FECHA<='%s'",
get_magic_quotes_gpc() ? $fecha_inicio: addslashes($fecha_inicio), get_magic_quotes_gpc() ? $fecha_fin : addslashes($fecha_fin));
$resultados = mysql_query($query, $turno) or die(mysql_error());
}
$readonly = "readonly=\"readonly\"";
izq();
?>
<h1 align="center">Buscar registros anteriores </h1>
<form action="<?=$_SERVER["PHP_SELF"]?>" method="get">
<table width="300px" align="center">
<tr>
<td><b>Fecha de inicio:</b></td>
<td><input type="text" id="fecha_inicio" name="fecha_inicio" value="<?=$fecha_inicio_str?>" /></td>
</tr>
<tr>
<td><b>Fecha de fin:</b></td>
<td><input type="text" id="fecha_fin" name="fecha_fin" value="<?=$fecha_fin_str?>" /></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" name="boton" value="Buscar" /></td>
</tr></table>
</form>

<br />
<br />
<table class="resultados" align="center">
<tr class="no-borde">
<?
if ($pagina>0) echo "<td><a class=\"boton\" href=\"buscar.php?pagina=".($pagina-1)."&fecha_inicio=".$fecha_inicio_str."&fecha_fin= ".$fecha_fin_str."\">Anterior</a></td>\n";
else echo "<td>&nbsp;</td>";
echo "<td>&nbsp;</td>";
if ($FILAS_POR_PAGINA*($pagina+1) < mysql_num_rows($resultados)) echo "<td><a class=\"boton\" href=\"buscar.php?pagina=".($pagina+1)."&fecha_ini cio=".$fecha_inicio_str."&fecha_fin=".$fecha_fin_s tr."\">Siguiente</a></td>\n";
else echo "<td>&nbsp;</td>";
?>
</tr>
</table>

<?
while ($datos = mysql_fetch_array($result, MYSQL_BOTH)) {
//Convertimos la fecha a un formato legible
$fecha = explode("-",$datos["FECHA"]);
$fecha_str = $fecha[2] . "-" . $fecha[1] . "-" . $fecha[0];
?>
<table align="center">
<tr valign="baseline">
<td nowrap align="right">FECHA:</td>
<td align="left"><?=$fecha_str?></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">TURNO:</td>
<td align="left"><?=$datos["TURNO"]?>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">LINEA 1-2:</td>
<td align="left"><textarea name="LINEA12" cols="80" rows="8" <?=$readonly?>><?=$datos["LINEA12"]?></textarea> </td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">LINEA 3-4:</td>
<td align="left"><textarea name="LINEA34" cols="80" rows="8" <?=$readonly?>><?=$datos["LINEA34"]?></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">CF-SS</td>
<td align="left"><textarea name="CFSS" cols="80" rows="8" <?=$readonly?>><?=$datos["CFSS"]?></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">CF-FV:</td>
<td align="left"><textarea name="CFFV" cols="80" rows="8" <?=$readonly?>><?=$datos["CFFV"]?></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">CF-HP/PHP/CF-AH:</td>
<td align="left"><textarea name="CFHPPHPCFAH" cols="80" rows="8" <?=$readonly?>><?=$datos["CFHPPHPCFAH"]?></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">USRD/USCC/E.A.LAM:</td>
<td align="left"><textarea name="USRDUSCCEALAM" cols="80" rows="8" <?=$readonly?>><?=$datos["USRDUSCCEALAM"]?></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">CF-PL2:</td>
<td align="left"><textarea name="CFPL2" cols="80" rows="8" <?=$readonly?>><?=$datos["CFPL2"]?></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">3FPL/3FFV:</td>
<td align="left"><textarea name="3FPL3FFV" cols="80" rows="8" <?=$readonly?>><?=$datos["3FPL3FFV"]?></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">C+C/I+D+I/FT:</td>
<td align="left"><textarea name="CCIDIFT" cols="80" rows="8" <?=$readonly?>><?=$datos["CCIDIFT"]?></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">EDAR:</td>
<td align="left"><textarea name="EDAR" cols="80" rows="8" <?=$readonly?>><?=$datos["EDAR"]?></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right" valign="top">SERV/MANNTO:</td>
<td align="left"><textarea name="SERVMANNTO" cols="80" rows="8" <?=$readonly?>><?=$datos["SERVMANNTO"]?></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">SOSA:</td>
<td align="left"><input type="text" name="SOSA" <?=$readonly?> value="<?=$datos["SOSA"]?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">ALGIBE</td>
<td align="left"><input type="text" name="ALGIBE" <?=$readonly?> value="<?=$datos["ALGIBE"]?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">D-7001:</td>
<td align="left"><input type="text" name="D7001" <?=$readonly?> value="<?=$datos["D7001"]?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">D-417:</td>
<td align="left"><input type="text" name="D417" <?=$readonly?> value="<?=$datos["D417"]?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">GRUPOS DE FRIO :</td>
<td align="left"><input type="text" name="GRUPOSDEFRIO" <?=$readonly?> value="<?=$datos["GRUPOSDEFRIO"]?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">CLORO :</td>
<td align="left"><input type="text" name="CLORO" <?=$readonly?> value="<?=$datos["CLORO"]?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">ENTRANTE:</td>
<td align="left"><input type="text" name="ENTRANTE" <?=$readonly?> value="<?=$datos["ENTRANTE"]?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">SALIENTE:</td>
<td align="left"><input type="text" name="SALIENTE" <?=$readonly?> value="<?=$datos["SALIENTE"]?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">V&ordm;B&ordm; JEFE MANTTO.:</td>
<td align="left"><input type="checkbox" <? if ($datos["VBJEFEMANNTO"]!="") echo "checked=\"checked\""?> <? if ($readonly!="") echo "disabled=\"disabled\""?> name="VBJEFEMANNTO" value="1" ></td>
</tr>
</table>
<?
}?>