Jump to content

[SOLVED] strtotime and date() functions.


gerkintrigg

Recommended Posts

I'm having a problem trying to work out if a series of parsed variables (dates for a calendar-type booking system) are consecutive... It keeps coming up with an error on the first iteration and i think the problem lies with the $tomorrow variable...

 

Could someone please have a look at this code and let me know what I'm doing wrong?

 

The commented out code helped me to de-bug but is probably not necessary. It's included anyway to help you out if need be.

 

Here's the code:

<?php 
include 'editable/customisable_variables.php';
$root=$url;
include '../includes/db.php';
$price=0;
$errors='?property='.$_REQUEST['property'];
//echo $_REQUEST['property'];

//set day counter to zero:
$no_of_days=0;
$not_consecutive='n';

foreach($_POST as $varName => $value) { 
if (($value !="Submit") && ($varName!="Submit") && ($varName!="a")){
	if ($no_of_days>=1){
		//echo 'value= '.$value.'<BR><BR><BR>';
		//set the day of this iteration:
		$today=strtotime($value);

		// write the session variable for the start date:
		//echo $no_of_days;
		//echo 'today = '.date('d/m/Y',$today).' ';
		if ($no_of_days==1){
			$_SESSION['start_date']=date('l d F Y',strtotime($value));
			//echo $_SESSION['start_date'];
		}
		else{
			//echo $no_of_days;

			//echo 'next = '.date('d/m/Y',$next).'<BR><BR>';
			if (($tomorrow!=$today)){
			$not_consecutive='y';
			//echo '#########'.$value.'#######################<BR>';
		}
	}
	//echo $no_of_days;
	//echo 'Start after= '.date('d/m/Y',$today).' ';
	//echo 'next = '.date('d/m/Y',$tomorrow).'<BR><BR>';
	//echo date('d/m/Y',$today).'<br>';
	$price_q="SELECT price FROM rate WHERE cottage_id='".$_REQUEST['property']."' && date='".date('Y-m-d',$today)."'";
	$price_sql=mysql_query($price_q);
	$price_r=mysql_fetch_array($price_sql);

	$price=$price+$price_r['price'];
}
	$no_of_days++;

	//echo '<BR><BR> Tomorrow='.date('d/m/Y',$tomorrow).'<BR>';
}
$tomorrow=strtotime('+1 day',$today);
}
// output today variable:
//echo $_SESSION['start_date'];



/*if (($no_of_days-1)<$minimum_no_of_days_booking){
$errors.='&not_minimum=y';
}

if ($not_consecutive=='y'){
$errors.='&consecutive=n';
}
//echo $price;
$_SESSION['price']=$price;
// if there are errors with the request, then return the user back with the error in the URL.
if ($errors!='?property='.$_REQUEST['property']){
$go = $root.'availability_check.php'.$errors;
header("Location: ".$go);
}
else{
$go = $root.'availability_check2.php'.$errors;
header("Location: ".$go);
}*/
?>

 

Thanks

Link to comment
Share on other sites

I'm having a problem trying to work out if a series of parsed variables (dates for a calendar-type booking system) are consecutive... It keeps coming up with an error on the first iteration and i think the problem lies with the $tomorrow variable...

 

What error does it come up with, and on what input?

Link to comment
Share on other sites

all input it just redirects me telling me that all dates are NOT consecutive - but they are. it works the second time I post the information. I wasn't sure if I was writing a session or a variable somewhere that it needs to work properly, because the first time the script runs, it fails, then after that it works fine.

 

I just want to make sure it works first time.

 

thanks.

Link to comment
Share on other sites

no worries... I sorted it out... here's the solution:

 

<?php 
include 'editable/customisable_variables.php';
$root=$url;
include '../includes/db.php';
$price=0;
$errors='?property='.$_REQUEST['property'];

//set day counter to zero:
$no_of_days=0;
$not_consecutive='n';

foreach($_POST as $varName => $value) { 
if (($value !="Submit") && ($varName!="Submit") && ($varName!="a")){
	if ($no_of_days==0){
		$_SESSION['start_date']=date('l d F Y',strtotime($value));
	}
	$today=strtotime($value);
	if ($no_of_days>=1){
		if ($no_of_days!=1){
			if (($tomorrow!=$today)){
			$not_consecutive='y';
		}
	}
	$_SESSION['end_date']=date('l d F Y',strtotime($value));
}
	$no_of_days++;
	$price_q="SELECT price FROM rate WHERE cottage_id='".$_REQUEST['property']."' && date='".date('Y-m-d',$today)."'";
	$price_sql=mysql_query($price_q);
	$price_r=mysql_fetch_array($price_sql);

	$price=$price+$price_r['price'];
}
$tomorrow=strtotime('+1 day',$today);

}

if (($no_of_days)<$minimum_no_of_days_booking){
$errors.='&not_minimum=y';
}



if ($not_consecutive=='y'){
$errors.='&consecutive=n';
}

$_SESSION['price']=$price;
// if there are errors with the request, then return the user back with the error in the URL.
if ($errors!='?property='.$_REQUEST['property']){
$go = $root.'availability_check.php'.$errors;
header("Location: ".$go);
}
else{
$go = $root.'availability_check2.php'.$errors;
header("Location: ".$go);
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.