Page 1 of 1
Resevation calendar
Posted: Sun Apr 10, 2005 9:38 am
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
Re: Resevation calendar
Posted: Sun Apr 10, 2005 10:07 am
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
Posted: Mon Apr 11, 2005 4:30 am
by Phoenixheart
Yeah, sometimes it's more easier using varchar [50] instead of DateTime

A little cheat doesn't hurt!
Posted: Mon Apr 11, 2005 10:36 am
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
Posted: Mon Apr 11, 2005 10:44 am
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
?>
Posted: Mon Apr 11, 2005 10:57 am
by timvw
PHOENIXHEART wrote:Yeah, sometimes it's more easier using varchar [50] instead of DateTime

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
Posted: Mon Apr 11, 2005 11:52 am
by ddragas
Thank you all for reply.
It works great.
Posted: Mon Apr 18, 2005 5:39 am
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.
Posted: Mon Apr 18, 2005 5:50 am
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.
Posted: Mon Apr 18, 2005 7:02 am
by Phoenixheart
OK, OK. I'm new to both php and mysql, gee

Posted: Mon Apr 18, 2005 7:19 am
by Phoenixheart
timvw wrote:because i only know situations where it is a major PITA
PITA? Why is it a PITA anyway?
Posted: Mon Apr 18, 2005 7:43 am
by feyd
change date formating.. see how fun it is to deal with.
