Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/09/2004, 06:43
Avatar de midpunto
midpunto
 
Fecha de Ingreso: enero-2004
Ubicación: España Palma de mallorca
Mensajes: 118
Antigüedad: 20 años, 3 meses
Puntos: 0
comparar fechas por temporadas con bucle

Hola...
estoy realizando una aplicacion de alquiler de coches que eta casi lista pero tengo un problema vastante grave:

En esta aplicacion tengo una bd con los campos: coche, fechainciot1,fechafint1,fechainciot2,fechafint2,fe chainciot3,fechafint3,fechainciot4,fechafint4 (en formato date mysql aaaa-mm-dd), y los campos de valor segun los dias,2t1 | 2t2 | 2t3 | 2t4 (2 o menos de 2 dias), 6t1 | 6t2 | 6t3 | 6t4 (6 o menos de 6 dias), 13t1 | 13t2 | 13t3 | 13t4 (13 o menos de 13 dias), 20t1 | 20t2 | 20t3 | 20t4 (20 o menos de 20 dias)28t1 | 28t2 | 28t3 | 28t4 (28 o mas de 28 dias).
Luego para la pagina de consulta he construido un formulario con el siguiente contenido: un campo para seleccionar el auto, otra para fecha inicio y otro para fecha de fin. estos son auto | fecha | y fecha2. Desde aqui envio los datos al siguiente script en el cual tengo el problema de que solamente me realiza el calculo cumpliendo la ultima condicion que se refiere a la ultima temporada t4...:

<?php require_once('../Connections/connect.php'); ?>
<?php
// variables fecha de formulario
$fecha = $_POST[fecha];
$fecha2 = $_POST[fecha2];
$_POST[auto];
mysql_select_db($database_connect, $connect);
$query_Recordset1 = "SELECT * FROM tarifas WHERE tarifas.id=$auto";
$Recordset1 = mysql_query($query_Recordset1, $connect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
//funcion calculo de dias::::
function dias_entre_fechas($fecha, $fecha2)
{
$dia1 = strtok($fecha, "/");
$mes1 = strtok("/");
$anyo1 = strtok("/");

$dia2 = strtok($fecha2, "/");
$mes2 = strtok("/");
$anyo2 = strtok("/");

$num_dias = 0;

if ($anyo1 < $anyo2)
{
$dias_anyo1 = date("z", mktime(0,0,0,12,31,$anyo1)) - date("z", mktime(0,0,0,$mes1,$dia1,$anyo1));
$dias_anyo2 = date("z", mktime(0,0,0,$mes2,$dia2,$anyo2));
$num_dias = $dias_anyo1 + $dias_anyo2;
}
else
$num_dias = date("z", mktime(0,0,0,$mes2,$dia2,$anyo2)) - date("z", mktime(0,0,0,$mes1,$dia1,$anyo1));

return $num_dias;
}
?>
<?

$dias = dias_entre_fechas($fecha, $fecha2)+1;//llamo la funcion de calculo de dias y le sumo un dia
//giro las fechas
$fecha = $_POST["fecha"];
$ArrayFecha =explode('/', $fecha);
$fecha = $ArrayFecha[2] .'/'.$ArrayFecha[1] .'/'.$ArrayFecha[0] ;

$fecha2 = $_POST["fecha2"];
$ArrayFecha =explode('/', $fecha2);
$fecha2 = $ArrayFecha[2] .'/'.$ArrayFecha[1] .'/'.$ArrayFecha[0] ;

$varaux = $fecha ;

if ($row_Recordset1['fechainiciot1'] <= $varaux and $row_Recordset1['fechafint1'] <= $fecha2);
{
if ($dias <= 2)
{
$importe = $dias * $row_Recordset1['2t1'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 6)
{
$importe = $dias * $row_Recordset1['6t1'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 13)
{
$importe = $dias * $row_Recordset1['13t1'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 20)
{
$importe = $dias * $row_Recordset1['20t1'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 27)
{
$importe = $dias * $row_Recordset1['27t1'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias >= 28)
{
$importe = $dias * $row_Recordset1['28t1'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($row_Recordset1['fechainiciot2'] <= $varaux and $row_Recordset1['fechafint2'] <= $fecha2);
{
if ($dias <= 2)
{
$importe = $dias * $row_Recordset1['2t2'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 6)
{
$importe = $dias * $row_Recordset1['6t2'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 13)
{
$importe = $dias * $row_Recordset1['13t2'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 20)
{
$importe = $dias * $row_Recordset1['20t2'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 27)
{
$importe = $dias * $row_Recordset1['27t2'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias >= 28)
{
$importe = $dias * $row_Recordset1['28t2'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($row_Recordset1['fechainiciot3'] <= $varaux and $row_Recordset1['fechafint3'] <= $fecha2);
{
if ($dias <= 2)
{
$importe = $dias * $row_Recordset1['2t3'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 6)
{
$importe = $dias * $row_Recordset1['6t3'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 13)
{
$importe = $dias * $row_Recordset1['13t3'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 20)
{
$importe = $dias * $row_Recordset1['20t3'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 27)
{
$importe = $dias * $row_Recordset1['27t3'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias >= 28)
{
$importe = $dias * $row_Recordset1['28t3'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($row_Recordset1['fechainiciot4'] <= $varaux and $row_Recordset1['fechafint4'] <= $fecha2);
{
if ($dias <= 2)
{
$importe = $dias * $row_Recordset1['2t4'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 6)
{
$importe = $dias * $row_Recordset1['6t4'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 13)
{
$importe = $dias * $row_Recordset1['13t4'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 20)
{
$importe = $dias * $row_Recordset1['20t4'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias <= 27)
{
$importe = $dias * $row_Recordset1['27t4'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}
else if ($dias >= 28)
{
$importe = $dias * $row_Recordset1['28t4'];
header("Location: ../reserv.php?total=$importe&fecha1=$varaux&fecha2=$f echa2&auto=$auto&dias=$dias");
}

else
{
echo 'alert(Se ha encontrado un error)';
header("Location: ../error_calculo.php");
}
}
}
}
}

?>
<?php
mysql_free_result($Recordset1);
//header("Location: ../reserv.php?total=$importelicacion&fecha1=$fecha&fe cha2=$fecha2&auto=$auto");//envio los resultados al formulario de salida
//echo $multiplicacion;
?>

Espero que alguien me pueda dar alguna orientacion o explicarme alguna otra manera de hacer esto, necesito ayuda!!!!!!!!. Gracias de antemano.