Resevation calendar

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Resevation calendar

Post by ddragas »

Hi all.

What I want to create is year resevation calendar for accommodations (appartaments, rooms, hotels), but I'm not sure how to start.

Should I make table in database with 365 (or more) fields or what?

If somebody could point me on wright direction for coding

Thank you
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Re: Resevation calendar

Post by anjanesh »

ddragas wrote:Should I make table in database with 365 (or more) fields or what?
Create 2 fields - From and To - both of DateTime format
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Post by Phoenixheart »

Yeah, sometimes it's more easier using varchar [50] instead of DateTime :P A little cheat doesn't hurt!
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

Ok

So far this is my code.

Code: Select all

<?
$slobodno = " bgcolor=\"#00FF00\"";
$mogucnost = " bgcolor=\"#FFFF00\"";
$zauzeto = " bgcolor=\"#FF0000\"";

$prvi_datum = "5/25/2005";
$drugi_datum = "6/15/2005";
$godina="2005";


echo "<table width=\"70%\"  border=\"1\" align=\"center\">";
echo "<tr>";
echo "<td width=\"5%\" align=\"center\" bgcolor=\"#3399FF\">Mjesec</td><td colspan=\"31\" bgcolor=\"#3399FF\"><div align=\"center\" >Dani</div></td></tr>";
for ($i = 1; $i <= 12; $i++) {
	echo "<td align=\"center\" bgcolor=\"#3399FF\">" . $i . "</td>";
    $broj_dana = cal_days_in_month (CAL_GREGORIAN, $i, $godina);
	
			for ($i1 = 1; $i1 <= $broj_dana; $i1++) {
			
				$datum11 = $i . '/' . $i1 . '/' . $godina; 
				
				if (($prvi_datum <= $datum11) and ($drugi_datum >= $datum11 )){echo "<td width=\"4%\" align=\"center\"  bgcolor=\"#FF0000\">$i1</td>";
				} else { echo "<td width=\"4%\" align=\"center\"  $slobodno >$i1</td>";}
				
				
				 }
				echo "</tr><br>";

}
echo "</table>";

?>

What I wanted with this code is to paint all tables in colour red between two dates

first date 5/25/2005
second date 6/15/2005

but it does not.


What am I doing wrong?

Regards ddragas



Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post by Bennettman »

mktime()

What you want to do is convert the DB dates ($prvi_datum, $drugi_datum and $datumll) to a timestamp, and then compare them, instead of comparing M/D/Y strings.

Code: Select all

<?php

$prvi_datum = mktime(0, 0, 0, 5, 25, 2005);
$drugi_datum = mktime(0, 0, 0, 6, 15, 2005);

...

$datumll = mktime(0, 0, 0, $i, $il, $godina);

...

// then compare as usual

?>
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

PHOENIXHEART wrote:Yeah, sometimes it's more easier using varchar [50] instead of DateTime :P A little cheat doesn't hurt!
would be nice if you could give us an example where it is easier...
because i only know situations where it is a major PITA
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

Thank you all for reply.

It works great.
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Post by Phoenixheart »

timvw wrote: would be nice if you could give us an example where it is easier...
because i only know situations where it is a major PITA
Ya know, in some regions the date time format is far different than in USA.
For an ex, in my country (Vietnam) it will be in this sequence:
Today is Wed, Day 1 Month April Year 2005
Not Wed,April 1st, 2005 :)
So I said sometimes a varchar is easier than a datetime.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

PHOENIXHEART wrote:
timvw wrote: would be nice if you could give us an example where it is easier...
because i only know situations where it is a major PITA
Ya know, in some regions the date time format is far different than in USA.
For an ex, in my country (Vietnam) it will be in this sequence:
Today is Wed, Day 1 Month April Year 2005
Not Wed,April 1st, 2005 :)
So I said sometimes a varchar is easier than a datetime.
I cant see an advantage AT ALL for using varchar(50) for dates...in 99.9% of cases it would be rediculous to do this, and especially in this case. Storing unix timestamps would be the way to go IMO.

By using Unix timestamps, you can output the dates in any format you wish.
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Post by Phoenixheart »

OK, OK. I'm new to both php and mysql, gee :D
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Post by Phoenixheart »

timvw wrote:because i only know situations where it is a major PITA
PITA? Why is it a PITA anyway?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

change date formating.. see how fun it is to deal with. :)
Post Reply