All, 

I am having an issue getting my cgi calender to print
correctly. Any help or hints would be appreciated!
I was thinking of manipulating the @weeks_anonymous
array with select dayofweek(curdate()) rather than
using hardcoed undef's

Problem: cgi calender daynames are not matching up
with dates. For example: Todays date 02/27/2007 is
being printed under Thursday instead of Tuesday.

Sun Mon Tues Wed Thurs Fri Sat 
Feb 12, 07 Feb 13, 07 Feb 14, 07 Feb 15, 07 
Feb 16, 2007 Feb 17, 2007 Feb 18, 2007 Feb 19, 2007
Feb 20, 2007 Feb 21, 2007 Feb 22, 2007 
Feb 23, 2007 Feb 24, 2007 Feb 25, 2007 Feb 26, 2007
Feb 27, 2007 Feb 28, 2007 Mar 1, 2007 
Mar 2, 2007 Mar 3, 2007 Mar 4, 2007 Mar 5, 2007 Mar 6,
2007 Mar 7, 2007 Mar 8, 2007 
Mar 9, 2007 Mar 10, 2007 Mar 11, 2007 Mar 12, 2007 Mar
13, 2007 Mar 14, 2007  

wherein today the 27th lines up with Thursday when
executing this code.  I need it to correctly line up
with Tuesday.  Finally, I am unable to use
HTML::Calander modules so this is not an option.

#!/usr/bin/perl

use strict;
use warnings;

require "dbi-lib.pl";              
use CGI qw/:standard *table start_ul/,
(-unique_headers);
use CGI::Carp qw(fatalsToBrowser);
use DBI;
my $cgi = new CGI;
local $sth;

#----------------------#
# Function calls       #
#----------------------#

print_header();
initialize_dbi();

#----------------#
# Begin Main     #
#----------------#


print $cgi->header(),
      $cgi->start_html ('Oreilly SQL Class, Lesson
11'),               # Header
      $cgi->h1 ({-style=>'Color:blue'},'Derek\'s SQL
Class');          # Body

      print "<u>",$cgi->strong('Date/Time CGI
Table:'),"</u><p>";
      print $cgi->caption('MySQL calendar table
output, Lesson 11:');
      print "<p>";
      
      run_statement( "select date_format(curdate(),
'%b %e, %Y');" );
      my $today = $sth->fetchrow;
        
      run_statement("select dayofweek(curdate() );" );
      my $dayofweek = $sth->fetchrow;
      print $dayofweek;
  
      #&run_statement( "select
date_format(curdate()-2,'%W');" );                    
   
      #my $twodayago = $sth->fetchrow;
      #print "$twodayago <p>";

my @WeekDays = qw(Sunday Monday Tuesday Wednesday
Thursday Friday Saturday);
my ($day,$week,)               = (0,0);
my (@weeks, @weeks_anonymous,) = ((),());

foreach $day ('-15' .. '15') {
    run_statement( "select
date_format(date_add(curdate(), interval '$day' day),
'%b %e, %Y');" );
    push (@weeks, $sth->fetchrow);
} 

## Begin Table ##

print table({border=>undef});
print Tr ({-align=>'CENTER',-valign=>'TOP'}, td
([EMAIL PROTECTED]));
@weeks_anonymous = ( 
 [undef, undef, $weeks[0], $weeks[1], $weeks[2],
$weeks[3] ],
 
[$weeks[4], $weeks[5], $weeks[6], $weeks[7],
$weeks[8],  $weeks[9],  $weeks[10] ],

 [$weeks[11], $weeks[12], $weeks[13], $weeks[14],
$weeks[15], $weeks[16], $weeks[17] ],

 [$weeks[18], $weeks[19], $weeks[20], $weeks[21],
$weeks[22], $weeks[23], $weeks[24]  ],

 [$weeks[25], $weeks[26], $weeks[27], $weeks[28],
$weeks[29], $weeks[30], $weeks[31] ],
                                             
);

foreach $element (@weeks_anonymous) {
    print Tr({-align=>'CENTER',-valign=>'TOP'});
    for $date (@{$element}) { 
        if (! defined $date) { 
            print td ('');
        } 
        elsif ($date eq $today) {   
            print td(strong($date));  
        } 
        else {
            print td ($date);
        }
    }
    print $cgi->end_Tr;
}
        
print $cgi->end_html;


 


 
____________________________________________________________________________________
The fish are biting. 
Get more visitors on your site using Yahoo! Search Marketing.
http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to