Professional Web Applications Themes

Display 7 day calenday - PHP Development

The below code works greate for displaying a monthly calendar, but I'm trying to modify it so that it only shows a seven day week calendar. What should I do to modify it. <?php function getDaysInMonth($thisYear,$thisMonth){ $date=getdate(mktime(0,0,0,$thisMonth+1,0,$thisYea r)); return $date["mday"]+1; } function getArrayMonth($datetime){ //get basic month information and initialize starter values. $dateArray = getdate($datetime); $mon = $dateArray['mon']; $year = $dateArray['year']; $numDaysInMonth = getDaysInMonth($year,$mon); $week=1; //for each day, get the current day's information and store in a result array // for that day, the week and the day of the week. //finally if that day is the last day of the ...

  1. #1

    Default Display 7 day calenday

    The below code works greate for displaying a monthly calendar, but I'm
    trying to modify it so that it only shows a seven day week calendar.
    What should I do to modify it.

    <?php
    function getDaysInMonth($thisYear,$thisMonth){
    $date=getdate(mktime(0,0,0,$thisMonth+1,0,$thisYea r));
    return $date["mday"]+1;
    }
    function getArrayMonth($datetime){

    //get basic month information and initialize starter
    values.
    $dateArray = getdate($datetime);
    $mon = $dateArray['mon'];
    $year = $dateArray['year'];
    $numDaysInMonth = getDaysInMonth($year,$mon);
    $week=1;


    //for each day, get the current day's information and
    store in a result array
    // for that day, the week and the day of the week.
    //finally if that day is the last day of the week,
    start a new week.
    for ($i=1; $i < $numDaysInMonth;$i++){

    $timestamp = mktime(0,0,0,$mon,$i,$year);
    $dateArray = getdate($timestamp);
    $result[$i]=array('wday'=>$dateArray['wday'],'week'=>$week,'timestamp'=>$timestamp);
    if ($dateArray['wday']==6){
    $week=$week+1;
    }
    }

    return $result;

    }
    function getHTMLCalendar($datetime){
    $arrayCalendar = getArrayMonth($datetime);
    print "<TABLE>\n";
    $week=1;
    print "<tr>";
    //add initial padding to month
    for ($start=1;$start<=$arrayCalendar[1]['wday'];
    $start=$start+1)
    print "<td></td>";


    // for each day make a cell with
    $lastday=1; //use for end month padding later
    foreach ($arrayCalendar as $day => $result) {
    //if we change weeks, start a new row
    if ($week!=$result['week']){
    print "<td></tr><tr>"; //week row
    $week=$result['week'];
    }
    //start day cell
    print "<td>";
    print "<table>";
    print "<tr><td>";

    print date("D M j Y", $result['timestamp']);
    print "</td></tr>";
    print "<tr><td>";
    print "Put content here";
    print "</td></tr>";
    print "</table>";
    print "</td>\n"; //end day cell
    $lastday = $day;
    }


    //add final padding
    for ($start=1;$start<=6-$arrayCalendar[$lastday]['wday'];
    $start=$start+1)
    print "<td></td>";

    print "</tr>\n";

    print "</TABLE>\n";
    }
    getHTMLCalendar(time());

    ?>

    THanks.
    Steve Fitzgerald Guest

  2. #2

    Default Re: Display 7 day calenday

    Steve,

    Consider using the "w" parameter in the date() function to retrieve the
    number of days between a given day of the week and Sunday (the first day of
    the week).

    $today = mktime();
    $days_since_sunday = date('w', $today);

    With this info, you can build an array of days for the next seven days
    starting on that Sunday:

    for($i = 0; $i < 7; $i++) {
    $days[$i]['stamp'] = mktime(0, 0, 0, date('n', $today),
    (date('j', $today) + $i - $days_since_sunday), date('Y', $today));
    $days[$i]['pretty_date'] = date('g:i:s a, F j, Y', $days[$i]['stamp']);
    }

    If you need this calendar for some other week, just offset the mktime()
    function by the appropriate number of days:

    $today = mktime(0, 0, 0, date('n'), (date('j') - 7*$num_weeks_ago),
    date('Y'));

    HTH,
    Zac


    "Steve Fitzgerald" <sfmnetsys.com> wrote in message
    news:f1885463.0307090221.61946259posting.google.c om...
    > The below code works greate for displaying a monthly calendar, but I'm
    > trying to modify it so that it only shows a seven day week calendar.
    > What should I do to modify it.
    >
    > <?php
    > function getDaysInMonth($thisYear,$thisMonth){
    > $date=getdate(mktime(0,0,0,$thisMonth+1,0,$thisYea r));
    > return $date["mday"]+1;
    > }
    > function getArrayMonth($datetime){
    >
    > //get basic month information and initialize starter
    > values.
    > $dateArray = getdate($datetime);
    > $mon = $dateArray['mon'];
    > $year = $dateArray['year'];
    > $numDaysInMonth = getDaysInMonth($year,$mon);
    > $week=1;
    >
    >
    > //for each day, get the current day's information and
    > store in a result array
    > // for that day, the week and the day of the week.
    > //finally if that day is the last day of the week,
    > start a new week.
    > for ($i=1; $i < $numDaysInMonth;$i++){
    >
    > $timestamp = mktime(0,0,0,$mon,$i,$year);
    > $dateArray = getdate($timestamp);
    >
    $result[$i]=array('wday'=>$dateArray['wday'],'week'=>$week,'timestamp'=>$tim
    estamp);
    > if ($dateArray['wday']==6){
    > $week=$week+1;
    > }
    > }
    >
    > return $result;
    >
    > }
    > function getHTMLCalendar($datetime){
    > $arrayCalendar = getArrayMonth($datetime);
    > print "<TABLE>\n";
    > $week=1;
    > print "<tr>";
    > //add initial padding to month
    > for ($start=1;$start<=$arrayCalendar[1]['wday'];
    > $start=$start+1)
    > print "<td></td>";
    >
    >
    > // for each day make a cell with
    > $lastday=1; //use for end month padding later
    > foreach ($arrayCalendar as $day => $result) {
    > //if we change weeks, start a new row
    > if ($week!=$result['week']){
    > print "<td></tr><tr>"; //week row
    > $week=$result['week'];
    > }
    > //start day cell
    > print "<td>";
    > print "<table>";
    > print "<tr><td>";
    >
    > print date("D M j Y", $result['timestamp']);
    > print "</td></tr>";
    > print "<tr><td>";
    > print "Put content here";
    > print "</td></tr>";
    > print "</table>";
    > print "</td>\n"; //end day cell
    > $lastday = $day;
    > }
    >
    >
    > //add final padding
    > for ($start=1;$start<=6-$arrayCalendar[$lastday]['wday'];
    > $start=$start+1)
    > print "<td></td>";
    >
    > print "</tr>\n";
    >
    > print "</TABLE>\n";
    > }
    > getHTMLCalendar(time());
    >
    > ?>
    >
    > THanks.

    Zac Hester Guest

Similar Threads

  1. Replies: 0
    Last Post: June 4th, 04:42 PM
  2. Multiple DB Columns display in <cfselect display>
    By J. Random in forum Coldfusion Database Access
    Replies: 5
    Last Post: July 29th, 02:39 PM
  3. XML Display help
    By tempestmagi in forum Macromedia Flash Data Integration
    Replies: 0
    Last Post: March 21st, 05:16 PM
  4. LG 700S monitor display does not work for 1024x768 display
    By Sameer in forum Linux Setup, Configuration & Administration
    Replies: 1
    Last Post: August 13th, 12:29 PM
  5. How to display?
    By Ryan A in forum PHP Development
    Replies: 1
    Last Post: August 9th, 06:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139