Availability Calendar PHP Error Message

Re: Availability Calendar PHP Error Message

Postby dewhickey » Wed Jan 14, 2009 9:30 pm

Sorry to bother you again.

When I return to the calendar, shouldn't it be showing which dates are already selected? I see the dates selected in phpMyadmin, but they don't show up when the calendar loads or refreshes.

Thanks for all your help.

Pete
dewhickey
 
Posts: 15
Joined: Tue Jan 13, 2009 4:38 pm

Re: Availability Calendar PHP Error Message

Postby chris » Wed Jan 14, 2009 9:32 pm

yes, it should....
give me a sec to test my version (again)

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Availability Calendar PHP Error Message

Postby chris » Wed Jan 14, 2009 9:49 pm

Hi there,
I have checked the zipped version and everything appears to be ok (ie upload zip file to new location and installed new version)

In functions.inc.php, could you add an "echo" to the line that queries the db for each month to get the booked dates and then add a print_r() to show the results.

Change theses lines (starting ln 15):
Code: Select all
$sql="SELECT * FROM ".T_BOOKINGS." WHERE id_item=".$id." AND MONTH(the_date)=".$month." AND YEAR(the_date)=".$year."";
   if(!$res=mysql_query($sql))   die("ERROR checking id item availability dates");
   while($row=mysql_fetch_array($res)){
      $booked_days[$row["the_date"]]=$row["state"];
   }

to this (just for testing)
Code: Select all
echo "<br>".$sql="SELECT * FROM ".T_BOOKINGS." WHERE id_item=".$id." AND MONTH(the_date)=".$month." AND YEAR(the_date)=".$year."";
   if(!$res=mysql_query($sql))   die("ERROR checking id item availability dates");
   while($row=mysql_fetch_array($res)){
      $booked_days[$row["the_date"]]=$row["state"];
   }
echo "<br>".print_r($booked_days);

This should show us the actuall query being made and the resulting array of booked days (though it will probably be empty :( )

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Availability Calendar PHP Error Message

Postby dewhickey » Wed Jan 14, 2009 9:56 pm

This change showed the calendar, but above the calendar it displayed these several lines:

SELECT * FROM bookings_cal WHERE id_item=2 AND MONTH(the_date)=01 AND YEAR(the_date)=2009Array ( [2009-01-16] => [2009-01-08] => [2009-01-09] => [2009-01-10] => )
1
SELECT * FROM bookings_cal WHERE id_item=2 AND MONTH(the_date)=02 AND YEAR(the_date)=2009Array ( [2009-02-13] => )
1
SELECT * FROM bookings_cal WHERE id_item=2 AND MONTH(the_date)=03 AND YEAR(the_date)=2009Array ( [2009-03-12] => [2009-03-13] => am )
1
SELECT * FROM bookings_cal WHERE id_item=2 AND MONTH(the_date)=04 AND YEAR(the_date)=2009
1
SELECT * FROM bookings_cal WHERE id_item=2 AND MONTH(the_date)=05 AND YEAR(the_date)=2009
1
SELECT * FROM bookings_cal WHERE id_item=2 AND MONTH(the_date)=06 AND YEAR(the_date)=2009
1
SELECT * FROM bookings_cal WHERE id_item=2 AND MONTH(the_date)=07 AND YEAR(the_date)=2009
1
SELECT * FROM bookings_cal WHERE id_item=2 AND MONTH(the_date)=08 AND YEAR(the_date)=2009Array ( [2009-08-12] => )
1
SELECT * FROM bookings_cal WHERE id_item=2 AND MONTH(the_date)=09 AND YEAR(the_date)=2009
1
SELECT * FROM bookings_cal WHERE id_item=2 AND MONTH(the_date)=10 AND YEAR(the_date)=2009
1
SELECT * FROM bookings_cal WHERE id_item=2 AND MONTH(the_date)=11 AND YEAR(the_date)=2009
1
SELECT * FROM bookings_cal WHERE id_item=2 AND MONTH(the_date)=12 AND YEAR(the_date)=2009
1
dewhickey
 
Posts: 15
Joined: Tue Jan 13, 2009 4:38 pm

Re: Availability Calendar PHP Error Message

Postby chris » Wed Jan 14, 2009 10:03 pm

yes, I can see the outputted lines.
The query is getting the results OK.

Where have you add the $booked_days=array(); line that I mentioned earlier?
It looks like you might have added it after the query and thus overwriting the array defined by the query loop.

Do you use skype or msn? - we could probably solve this quicker if we could use one of them.
Send me a pm if you do and want to move this on via "chat"

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Availability Calendar PHP Error Message

Postby dewhickey » Wed Jan 14, 2009 10:11 pm

No, I don't have skype or msn running. Never got around to that.

This is where I put that array line in functions, starting on line 70:

// check if day is available
$booked_days=array();
if(array_key_exists($this_date,$booked_days)){
//echo "<br>".$booked_days[$this_date];
if($booked_days[$this_date]=="am") $day_image='cal_am_'.$day_counter.'.png';
elseif($booked_days[$this_date]=="pm") $day_image='cal_pm_'.$day_counter.'.png';
else $day_image='cal_on_'.$day_counter.'.png';
}
dewhickey
 
Posts: 15
Joined: Tue Jan 13, 2009 4:38 pm

Re: Availability Calendar PHP Error Message

Postby chris » Wed Jan 14, 2009 10:20 pm

That explains it - you are overwirting the array of dates that you have read from the data base.

This line:
$booked_days=array();
needs to be BEFORE the sql query is made to get the booked days from the db.
ie.:
Code: Select all
$booked_days=array();
   $sql="SELECT * FROM ".T_BOOKINGS." WHERE id_item=".$id." AND MONTH(the_date)=".$month." AND YEAR(the_date)=".$year."";
   if(!$res=mysql_query($sql))   die("ERROR checking id item availability dates");
   while($row=mysql_fetch_array($res)){
      $booked_days[$row["the_date"]]=$row["state"];
   }

CHris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Availability Calendar PHP Error Message

Postby dewhickey » Wed Jan 14, 2009 10:26 pm

Yes, it's all working perfectly, and I understand. I've done similar in my own php code. I'm learning. It will take time.

Thanks for all your help. You've been very kind and patient.

Pete
dewhickey
 
Posts: 15
Joined: Tue Jan 13, 2009 4:38 pm

Re: Availability Calendar PHP Error Message

Postby chris » Wed Jan 14, 2009 10:41 pm

no worries,
Most of the problems where caused by my bad zip file so I can't really complain ;)

As I mentioned before, good luck with the script - I hope it proves as useful for you as you expect.

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron