Hi, I am driving me crazy searching for scripts, however non works as most only display the result from the form.
I have a mysql-php script that checks availability and prices for the properties.
When the form is being sent (on wich only the dates are introduced - year-month and another select for day), the result is displayed on the same page using #divonpage.
Well, I like to take away the refreshing the page and jumping to the result and the solution is ajax, and if possible hijax so it will work with javascript disabled. And if without jquery better as I have a mootolsscript on those pages and with the photos the size of the documents are big.
Anyone knows a script that not only shows the dates from the form but all the selects in the mysql queries?
I will past the php code so you see its complicated (at least for me )
I cut what repeated as its very long.
The name of the property ($propiedad) doesn't come from mysql, it is declared manually on the pages.
Code:
<?php
include("conex/conexion.php");
if ($_POST['enviar']) {
$llegada = $month."-".$day;
$salida = $month2."-".$day2;
$monthyear = explode('-', $month);
$arrival_display = $day .' '. $monthyear[1] .' '. $monthyear[0];
$monthyear2 = explode('-', $month2);
$departure_display = $day2 .' '. $monthyear2[1] .' '. $monthyear2[0];
$arrival_display = ltrim($arrival_display, "0");
$arrival_display = str_replace(" 01", " Jan", $arrival_display);
$arrival_display = str_replace(" 02", " Feb", $arrival_display);
etc
$departure_display = ltrim($departure_display, "0");
$departure_display = str_replace(" 01", " Jan", $departure_display);
$departure_display = str_replace(" 02", " Feb", $departure_display);
etc
if ($salida > $llegada){
//miramos si disponible
$result = mysql_query ("SELECT DATE_FORMAT(llegada, '%e %b %Y') as lleg, DATE_FORMAT(salida, '%e %b %Y') as sal,tiporeserva, propiedad, TO_DAYS('$salida') - TO_DAYS('$llegada') as dias from bookings where ( propiedad = '$propiedad' )
AND (('$llegada' BETWEEN llegada AND date_sub(salida, interval +1 day))
or ('$salida' BETWEEN date_sub(llegada, interval -1 day) AND salida) or (llegada <= '$llegada' AND salida >= '$salida') or (llegada >= '$llegada' AND salida <= '$salida'))", $dbh);
if ($row = mysql_fetch_object($result)) {
if ($row->tiporeserva=="larga"){ echo "This property is available only for long term rentals, consult us for a price."; }
else {
do{
$propiedad = str_replace("_", " ", $propiedad);
echo "<span class='red'>$propiedad is occupied from ". $row->lleg ." until ". $row->sal ."</span><br>";
$availability="<span class='red'>No, $propiedad is not available from $arrival_display to $departure_display.</span>";
echo "</table> \n";
} while ($row = mysql_fetch_object($result));
}
}
else {
$sql = "SELECT llegada, salida, propiedad, TO_DAYS('$salida') - TO_DAYS('$llegada') as dias from bookings where ( propiedad = '$propiedad' ) AND ((llegada = '$salida') OR (salida = '$llegada'))";
$rows = mysql_fetch_assoc(mysql_query($sql));
$dias=$rows['dias'];
if ($salida==$rows['llegada'])
{ $availability= "<span class=\"red\">For dates $arrival_display to $departure_display, consultation is necessary as there is a booking arriving the same day as your
departure date.</span>";
if ($dias<7)
{
$half_round="Consultation is necessary as prices are based on 7 nights."; }
else {
// fin mirar si disponible
$result = mysql_query ("SELECT
(CASE WHEN ('$llegada' BETWEEN nov_inicio AND nov_fin and '$salida' BETWEEN nov_inicio AND nov_fin)
THEN sum(novbr) * (TO_DAYS('$salida') - TO_DAYS('$llegada')) ELSE NULL END) AS price,
(CASE WHEN ('$llegada' BETWEEN nov_inicio AND nov_fin and '$salida' > nov_fin)
THEN sum(novbr) * (TO_DAYS(dec_inicio) - TO_DAYS('$llegada'))ELSE NULL END) AS price1,
etc.
FROM precios where precios.id_propiedad = '$propiedad'
", $dbh);
while ($row = mysql_fetch_array($result)){
$price=$row["price"];
$price1=$row["price1"];
$price2=$row["price2"];
$price3=$row["price3"];
etc
}
$total=$price+$price1+etc;
$half_round = round(($total*2), 0)/2;
}}
elseif ($llegada==$rows['salida'])
{ $availability= "<span class=\"red\">For dates $arrival_display to $departure_display, consultation is necessary as there is a booking leaving the same day as your
arrival date.</span>";
if ($dias<7)
{
$half_round="Consultation is necessary as prices are based on 7 nights."; }
else {
// fin mirar si disponible
$result = mysql_query ("SELECT
(CASE WHEN ('$llegada' BETWEEN nov_inicio AND nov_fin and '$salida' BETWEEN nov_inicio AND nov_fin)
THEN sum(novbr) * (TO_DAYS('$salida') - TO_DAYS('$llegada')) ELSE NULL END) AS price,
(CASE WHEN ('$llegada' BETWEEN nov_inicio AND nov_fin and '$salida' > nov_fin)
THEN sum(novbr) * (TO_DAYS(dec_inicio) - TO_DAYS('$llegada'))ELSE NULL END) AS price1,
etc
FROM precios where precios.id_propiedad = '$propiedad'
", $dbh);
while ($row = mysql_fetch_array($result)){
$price=$row["price"];
$price1=$row["price1"];
$price2=$row["price2"];
$price3=$row["price3"];
etc
}
$total=$price+$price1+etc.;
$half_round = round(($total*2), 0)/2;
}}
else {
$sqls = "SELECT TO_DAYS('$salida') - TO_DAYS('$llegada') as dias from bookings ";
$rowss = mysql_fetch_assoc(mysql_query($sqls));
$dias=$rowss['dias'];
$propiedad = str_replace("_", " ", $propiedad);
$availability="<span class=\"red\">Yes, $propiedad is available from $arrival_display to $departure_display.</span>";
$propiedad = str_replace(" ", "_", $propiedad);
if ($dias<7)
{
$half_round="Consultation is necessary as prices are based on 7 nights."; }
else {
// fin mirar si disponible
// cambiar según semana santa
$result = mysql_query ("SELECT
(CASE WHEN ('$llegada' BETWEEN nov_inicio AND nov_fin and '$salida' BETWEEN nov_inicio AND nov_fin)
THEN sum(novbr) * (TO_DAYS('$salida') - TO_DAYS('$llegada')) ELSE NULL END) AS price,
(CASE WHEN ('$llegada' BETWEEN nov_inicio AND nov_fin and '$salida' > nov_fin)
THEN sum(novbr) * (TO_DAYS(dec_inicio) - TO_DAYS('$llegada'))ELSE NULL END) AS price1,
etc.
FROM precios where precios.id_propiedad = '$propiedad'
", $dbh);
while ($row = mysql_fetch_array($result)){
$price=$row["price"];
$price1=$row["price1"];
$price2=$row["price2"];
etc
}
$total=$price+$price1+etc.;
$half_round = round(($total*2), 0)/2;
}
}
}
}//end if salida mayor
else {echo "<span class=\"red\">There is an error with the dates please try again, arrival: $arrival_display and departure: $departure_display </span>";}
}
?>
<?php
mysql_close($dbh);
echo "<p class=\"resulttext\">Available: $availability<br>Price in euros: <span class=\"red\">$half_round</span><br>Nights: <span class=\"red\">$dias</span></p>";
?>
Well, I like to take away the refreshing the page and jumping to the result and the solution is ajax, and if possible hijax so it will work with javascript disabled.
There's a contradiction here. Or maybe I did not understand what you wanted to say. If javascript is disabled, no AJAX solution is possible, as AJAX is based on JavaScript.
There's a contradiction here. Or maybe I did not understand what you wanted to say. If javascript is disabled, no AJAX solution is possible, as AJAX is based on JavaScript.
function goAjax(form){
// send a request to something.php
return false
}
Now, if the javascript is enabled, the changes will be made via an AJAX request. If not, the form will submit data and you should do something to reload the document (either e redirect from that PHP file, or, maybe, even that submit.php could be exactly the document.
function goAjax(form){
// send a request to something.php
return false
}
Now, if the javascript is enabled, the changes will be made via an AJAX request. If not, the form will submit data and you should do something to reload the document (either e redirect from that PHP file, or, maybe, even that submit.php could be exactly the document.
Thanks, accessible is exactly what I wanted if possible.
The code you gave me, is it to add to the hijax example?
I tried, but the only thing I manage is to get the form submitted and being redirected to the action page where I get the result correctly, but cant manage to get on same page as it should.