www.webdeveloper.com
Results 1 to 2 of 2

Thread: calendar

  1. #1
    Join Date
    Mar 2006
    Location
    Canada
    Posts
    1,197

    calendar

    Hi

    below is code that creates a calendar that shows a calendar and two buttons that moves the calendar forward and back. I'm trying to add two select options, one for month and the other for year. to change the calendar. below is what I have but for some reason I cannot get the select options to work
    PHP Code:
                <?php

    include ('../config/db.php');
    $user_id $_SESSION['user_id'];

    // Check for a Month Change submission

    if ($_POST) {

    if(
    $_POST['user_select']){

    $date getdate(mktime(0,0,0,
      
    $_POST["month_now"],1,
      
    $_POST["year_now"]));

    } else {
    $date getdate();

    }

    // Subtract one from the month for previous, add one for next

    if ($_POST["submit"] == "Prev") {
        
    $_POST["month_now"]--;
        } else {
        
    $_POST["month_now"]++; }

    $date getdate(mktime(0,0,0,
      
    $_POST["month_now"],1,
      
    $_POST["year_now"]));

    } else {
    $date getdate();
    }

    $month_num $date["mon"];
    $month_name $date["month"];
    $year $date["year"];
    $date_today getdate(mktime(0,0,0,$month_num,1,$year));
    $first_week_day $date_today["wday"];
    $cont true;
    $today 27;



    while ((
    $today <= 32) && ($cont)) {
    $date_today getdate(mktime(0,0,0,$month_num,$today,$year));

    if (
    $date_today["mon"] != $month_num) {
    $lastday $today 1;
    $cont false;
    }

    $today++;
    }

    // allow for form submission to the script for forward and backwards

    echo"<form  method='POST' name='calendar' action='cal.php'>";


    // allow for form submission to the script for forward and backwards

    echo"<form  method='POST' name='calendar' action='cal.php'>";


    echo 
    '<select name="month_now" id="month_now">';
    $months = array('01'=>'January''02'=>'Febuary''03'=>'March''04'=>'April''05'=>'May''06'=>'June''07'=>'July''08'=>'August''09'=>'September''10'=>'October''11'=>'November''12'=>'December');
    $month = (isset($_POST['month_now']) and is_numeric($_POST['month_now'])) ? $_POST['month_num'] : date('m') ;
    foreach(
    $months as $number => $word)
    {
        echo 
    '  <option value="'.$number.'"'.(($number == $month)?' selected="selected"':'').'>'.$word.'</option>'."\n";
    }
    echo 
    '</select> ';

          echo
    '<select name="year_now" id="year_now">';
                
    $thisYear date('Y');
    $yearsN range($thisYear 2$thisYear 2);
    $yearsN array_reverse($yearsN);

    foreach(
    array_reverse($yearsN) as $value)
    {
      echo 
    '<option value ='.$value;
      if(
    $value == $thisYear)
      {
        echo 
    " selected='selected'";
      }
      echo 
    ">$value</option>\n";
    }

             echo
    '</select>';
             echo
    '<input type="submit" name="user_select" value="GO">';



    echo
    "<input type='hidden' name='month_now' value='$month_num'>
    <input type='hidden' name='year_now' value='
    $year'>
    <table align='center' width='200'>
    <tr><td><input type='submit' name='submit' value='Prev'></td>
        <td><div align='right'><input type='submit' name='button' value='Next'></div></td>
    </tr>
    </table>
    </form>

    <table width='200' height='200' border='1' cellspacing=0 cellpadding=2>
    <tr><td colspan='7'><div align='center'>
    $month_name $year</div></td></tr>
    <tr><td>Su</td><td>M</td><td>T</td><td>W</td><td>Th</td><td>F</td><td>Sat</td></
    tr>"
    ;

    // begin placement of days according to their beginning weekday

    $day 1;
    $wday $first_week_day;
    $firstweek true;
    while ( 
    $day <= $lastday) {

    $month_day = ($year.'-'.$month_num.'-'.$day); 

    if (
    $firstweek) {
    echo 
    "<TR>";
    for (
    $i=1$i<=$first_week_day$i++) {

    echo 
    "<td>  </td>";
    }

    $firstweek false;
    }


    if (
    $wday==0) {
    echo 
    "<tr>";


    }

    $cal_description mysql_query("SELECT * FROM calendar C WHERE C.event_date = '$month_day' AND C.userid = '$user_id'") or die (mysql_error());


    while (
    $r=mysql_fetch_assoc($cal_description)){

    $event_description $r['event_description'];
    $event_date $r['event_date'];
    $event_id $r['event_id'];
    $owner_id $r['userid'];
    $category $r['event_category'];

    $msgright .= '<tr>';

    switch (
    $category){

    case 
    "Birthday":
    $msgright .= "<td class='rowRight'><img src='../images/bCakeBullet.jpg' alt='bCake'></td>";
    break;

    case 
    "Anniversary":
    $msgright .= "<td class='rowRight'><img src='../images/weddingbandBullet.jpg' alt='wedding'></td>";
    break;

    case 
    "Family Event":
    $msgright .= "<td class='rowRight'><img src='../images/eventBullet.jpg' alt='event'></td>";
    break;

    case 
    "Family Trip":
    $msgright .= "<td class='rowRight'><img src='../images/airplaineBullet.jpg' alt='AirPlane'></td>";
    break;

    case 
    "Other":
    $msgright .= "<td class='rowRight'><img src='../images/questionMarkBullet.jpg' alt='QuestionMark'></td>";
    break;

    case 
    "":
    $msgright .= "<td class='rowRight'></td>";
    break;

    }

    $msgright .= "<td class='rowRight' >$event_date</td>";
    $msgright .= "<td class='rowRight'><a href='../eventCalendar/eventdisplay.php?event_id=$event_id&owner_id=$owner_id'>$event_description</a></td>";
    $msgright .= '</tr>';

    }


    // make each day linkable to the following result.php page

    if ( intval($month_num) < 10) { $new_month_num "0$month_num"; }
    elseif (
    intval($month_num) >= 10) { $new_month_num $month_num; }
    if ( 
    intval($day) < 10) { $new_day "0$day"; }
    elseif (
    intval($day) >= 10) { $new_day $day; }
    $link_date "$year-$new_month_num-$new_day";


    // add some color and make todays dat stand  out
    $today_year date("Y");
    $today_month date("F");
    $today_day date("j");

    if(
    $day == $today_day && $month_name == 
    $today_month && $year == $today_year)
    $colour lightblue;
    else
    $colour white;
    echo 
    "<td align=center bgcolor=$colour><a href=results.php?eventid=$link_date$day </a></td>";

    // show event description

    if ($wday==6) {
    echo 
    "</tr>\n";
    }

    $wday++;
    $wday $wday 7;
    $day++;

    }


    echo
    "</table>";

    ?>
    </p>
              
    </div>

            
    <div id="left">

    <?php include("../leftlinks.php"); ?>
    </div>
            </div>
        
    <div id="right">

       <p>
         <?PHP

    $c_year 
    date("$eventid");
    echo 
    $c_year;


    $get_Birthdays = ("SELECT P.owner_id, C.owner_id, S.owner_id, B.owner_id, U.user_id, P.parentdob, C.childdob, S.siblingdob, U.spousedob, U.DOB FROM parent P, children C, sibling S, users U, buddylink B WHERE U.user_id = '$user_id' AND C.owner_id = '$user_id' AND S.owner_id = '$user_id' AND P.owner_id = '$user_id' AND B.owner_id = '$user_id'");

    $birthdays mysql_query($get_Birthdays) or die ("Invalid query"mysql_error());


    ?>
       </p>
       <p>&nbsp;</p>
       <table class="columntable" cellspacing="2">
    <tr class="tableheader"><th class='Rdisplayhead' colspan='3'>Events for <? echo $month_name?> <? echo $year?></td><br></tr>
      <tr>
    <td class="rowRight" scope="row"></td>
    <td class="rowLeft" scope="row">Date</td>
    <td class="rowRight" scope="row">Description</td>
    <? echo $msgright?>
    </tr>

    <?php

    $get_Children_Birthdays 
    = ("SELECT * FROM children WHERE owner_id = '$user_id'");

    $children_birthdays mysql_query($get_Children_Birthdays) or die ("Invalid query"mysql_error());

    while (
    $child_R mysql_fetch_array($children_birthdays)){

    $childdob $child_R['childdob'];
    $childfirstname $child_R['childfirstname'];
    $childlastname $child_R['childlastname'];
    $child_array explode("-",$childdob);
    $child_birthday = ($year."-".$child_array[1]."-".$child_array[2]);
    $child_month_num $child_array[1];

    if(
    $month_num == $child_month_num){

    echo 
    "<tr>";

    echo
    "<td class ='rowRight'><img src='../images/bCakeBullet.jpg' alt='bCake'></td>";
    echo 
    "<td class ='rowLeft'>$child_birthday</td>";
    echo 
    "<td class='rowRight'>$childfirstname $childlastname</td>";
    echo 
    "</tr>";

    }else{
    }
        }

    /********************Sibling*************************/

    $get_sibling_Birthdays = ("SELECT * FROM sibling WHERE owner_id = '$user_id'");

    $sibling_birthdays mysql_query($get_sibling_Birthdays) or die ("Invalid query"mysql_error());

    while (
    $sibling_R mysql_fetch_array($sibling_birthdays)){

    $siblingdob $sibling_R['siblingdob'];
    $siblingfirstname $sibling_R['siblingfirstname'];
    $siblinglastname $sibling_R['siblinglastname'];
    $sibling_array explode("-",$siblingdob);
    $sibling_birthday = ($year."-".$sibling_array[1]."-".$sibling_array[2]);
    $sibling_month_num $sibling_array[1];

    if(
    $month_num == $sibling_month_num){

    echo 
    "<tr>";

    echo
    "<td class ='rowRight'><img src='../images/bCakeBullet.jpg' alt='bCake'></td>";
    echo 
    "<td class ='rowLeft'>$sibling_birthday</td>";
    echo 
    "<td class='rowRight'>$siblingfirstname $siblinglastname</td>";
    echo 
    "</tr>";

    }else{
    }
        }
    /*************************Parent Birth day Add**********************/
    $get_parent_Birthdays = ("SELECT * FROM parent WHERE owner_id = '$user_id'");

    $parent_birthdays mysql_query($get_parent_Birthdays) or die ("Invalid query"mysql_error());

    while (
    $parent_R mysql_fetch_array($parent_birthdays)){

    $parentdob $parent_R['parentdob'];
    $parentfirstname $parent_R['parentfirstname'];
    $parentlastname $parent_R['parentlastname'];
    $parent_array explode("-",$parentdob);
    $parent_birthday = ($year."-".$parent_array[1]."-".$parent_array[2]);
    $parent_month_num $parent_array[1];

    if(
    $month_num == $parent_month_num){

    echo 
    "<tr>";

    echo
    "<td class ='rowRight'><img src='../images/bCakeBullet.jpg' alt='bCake'></td>";
    echo 
    "<td class ='rowLeft'>$parent_birthday</td>";
    echo 
    "<td class='rowRight'>$parentfirstname $parentlastname</td>";
    echo 
    "</tr>";

    }else{
    }
        }


    </
    table>
    Kevin

  2. #2
    Join Date
    Oct 2005
    Location
    California
    Posts
    603
    is_numeric($_POST['month_now'])

    '09' etc will never be numeric. Did I analyze the right area you are having trouble with?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles