Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unique Calendar Problem--TOTALLY Baffled!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a unique roject I'm working opn and I'm totally baffled!

It's two calendars, side by side and in reverse order (May/April). First
you enter your Zip Code (have DB set up ewth UPS codes, zones, and
shipping dates), then you click on the date you'd like to have your
borchures delivered by.

A red sphere will appear on the delivery date, preceded two or more days
(depending upon the DB results) with a yellow sphere designatng the
shipping date. 5 days before that, a purple sphere, represnting the date
the press is run. Two days before this, a green sphere represnenting
when you'll receive (and hopefully approve same day) your proof. Back up
two more days and a blue sphere represents the latest date you must
upload your files to the printer.

PROBLEM: ANy sphere falling on a weekend miust be backed up to the
prvious Friday.

Sounds simple, but it's proving otherwise. Maybe I need to start all
over and re-evaluate my approach.

First problem, because of the way I've designed the script, is getting
balls to fall into the previous month if necessary, but I won't worry
about that now.

The BIG problem is getting Saturdays and Sundays ($wday ==0 && $wday
==6) to back up.

Here's a simplifed excerpt of what I've tried so far.

BTW: you can see the work in progress at

#################################################
//$day is ther numerical day of the mopnth and $wday is the
//numerical number of the day of week (Sun-Sat/ 0-6)

if (isset($delivery)){
$shipping = $delivery -2;
$print = $shipping -2;
$proof = $print -5;
$submit = $proof -2;

// bad code:
if(($day == $delivery) && ($wday == 0)){
$delivery = $delivery-2;
}elseif(($day == $delivery) && ($wday == 6)){
$delivery = $delivery-1;
}
// if this worked I'dd add if for each variable

if($day == $delivery){
print &quot;<td><a href=$PHP_SELF?delivery=$day>$day<BR>$red_ball</a></td>;}
elseif($day == $shipping){
print &quot;<td><a href=$PHP_SELF?delivery=$day>n$day<BR>$yellow_ball</a></td>;}
elseif($day == $print){
print &quot;<td><a href=$PHP_SELF?delivery=$day>$day<BR>$green_ball</a></td>&quot;;}
elseif($day == $proof){
print &quot;<td><a href=$PHP_SELF?delivery=$day>$day<BR>$purple_ball</a></td>&quot;;}
elseif($day == $submit){
print &quot;<td><a href=$PHP_SELF?delivery=$day>$day<BR>$blue_ball</a></td>&quot;;
}}
#################################################

Please don't respond by tewlling me what a bonehead I am. I know that.

Obviously this won't work, because it's cycling through each day, it doesn't
know what to do when it comes to a weekend day, so it does nothing, but it will
place the other spheres.

I'm afraid I'll either need to rethink my whole way of omplementing the script
or write complex class.

I'm a fairly cmopetent PHP pscripte, and I've looked at a dozen other calendar
scripts for inspiration, but nothing that covers anyting like this.

Any ideas would be greatly appreciated.

To give you an idea how the script draws the calendar:
#####################################################
$date=getdate();
$month_num=$date[&quot;mon&quot;];
$month_name=$date[&quot;month&quot;];
$This_Month=$date[&quot;month&quot;];
$year=$date[&quot;year&quot;];
$date_today=getdate(mktime(0,0,0,$month_num,1,$year));
$first_week_day=$date_today[&quot;wday&quot;];
$cont=true;
$today=27;
while(($today<=32)&&($cont)){
$date_today=getdate(mktime(0,0,0,$month_num,$today,$year));
if($date_today[&quot;mon&quot;]!=$month_num){
$lastday=$today-1;
$cont=false;
}
$today++;
}

// Here I've omitted calendar 1's header (Month name) and second row with weekday names

$day=1;
$wday=$first_week_day;
$firstweek=true;
while($day<=$lastday){
if($firstweek){
print &quot;<TR>&quot;;
if($wday < 6 && $day <= 0){
$colspan = (6-$wday);
print &quot;<TD COLSPAN=\&quot;$colspan\&quot; width=\&quot;20\&quot; background=\&quot;images/BlockRContent.gif\&quot; align=\&quot;center\&quot; Valign=\&quot;middle\&quot;>\n<IMG SRC=\&quot;images/BlockRContent.gif\&quot;></td>\n&quot;;
}
else{
print &quot;<TD width=\&quot;20\&quot; background=\&quot;images/BlockRContent.gif\&quot; align=\&quot;center\&quot; Valign=\&quot;middle\&quot;>\n<IMG SRC=\&quot;images/BlockRContent.gif\&quot;></td>\n&quot;;
}
$firstweek=false;
}
if($wday==0){
print &quot;<tr>\n&quot;;
}

/////// Omitted problem code shown in beginning

if($wday < 6 && $day >= $lastday){
$colspan = (7-$wday);
print &quot;<TD COLSPAN=\&quot;$colspan\&quot; background=\&quot;images/BlockRContent.gif\&quot; align=\&quot;center\&quot; Valign=\&quot;middle\&quot;>\n<IMG SRC=\&quot;images/BlockRContent.gif\&quot;></TD>\n</tr>\n&quot;;
}
elseif($wday == 6){
print &quot;</tr>\n&quot;;
}
$wday++;
$wday=$wday%7;
$day++;
}

//// Now start calendar two (April)

$first_week_day=$date_today[&quot;wday&quot;];
$date_today=getdate(mktime(0,0,0,$month_num,$today,$year));
if($date_today[&quot;mon&quot;]!=$month_num){
$lastday=$today-1;
$cont=false;
$today++;
}
 
What DB are you using ? ***************************************
Party on, dudes!
[cannon]
 
Then get your dates from there instead of PHP working them out , they are much more flexible.

select curdate(); = today
select date_sub(curdate(), interval 3 day); = 3 days ago other things to check on mysql.com
date_sub
date_add
date_format

this should give you every thing you need to calculate your whole array of dates in one go.

Fun with Dates im mysql, used with date_format(date,formatting)

%M Month name (January..December)
%W Weekday name (Sunday..Saturday)
%D Day of the month with English suffix (1st, 2nd, 3rd, etc.)
%Y Year, numeric, 4 digits
%y Year, numeric, 2 digits
%X Year for the week where Sunday is the first day of the week, numeric, 4 digits, used with '%V'
%x Year for the week, where Monday is the first day of the week, numeric, 4 digits, used with '%v'
%a Abbreviated weekday name (Sun..Sat)
%d Day of the month, numeric (00..31)
%e Day of the month, numeric (0..31)
%m Month, numeric (01..12)
%c Month, numeric (1..12)
%b Abbreviated month name (Jan..Dec)
%j Day of year (001..366)
%H Hour (00..23)
%k Hour (0..23)
%h Hour (01..12)
%I Hour (01..12)
%l Hour (1..12)
%i Minutes, numeric (00..59)
%r Time, 12-hour (hh:mm:ss [AP]M)
%T Time, 24-hour (hh:mm:ss)
%S Seconds (00..59)
%s Seconds (00..59)
%p AM or PM
%w Day of the week (0=Sunday..6=Saturday)
%U Week (0..53), where Sunday is the first day of the week
%u Week (0..53), where Monday is the first day of the week
%V Week (1..53), where Sunday is the first day of the week. Used with '%X'
%v Week (1..53), where Monday is the first day of the week. Used with '%x'
%% A literal `%'.
------------------------
select DATE_FORMAT('1997-10-04 22:23:00', '%H:%i:%s');
-> '22:23:00'
***************************************
Party on, dudes!
[cannon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top