PHP Table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sireen
    New Member
    • May 2007
    • 2

    PHP Table

    Hello everybody,

    am New in PHP. I would appreciate some help in the below code . What i need is a yearly calender that displays only the months without days .So i can load the data on a monthly basis.


    <?php
    defined( '_VALID_MOS' ) or die( 'Restricted access' );
    require_once( $mainframe->getPath( 'front_html' ) );

    // page title
    $mainframe->setPageTitle ( 'Callout' );

    echo "

    <center>";



    //Check for a Month Change submission

    if (isset($_POST['submit']))
    {
    $submit = $_POST['submit'];
    $month_now = $_POST["month_now"];
    $year_now = $_POST["year_now"];
    // Subtract one from the month for previous, add one for next
    //<body bgcolor='pink'>
    if ($submit == "Prev")
    {

    if($month_now >6 && $year_now >= 2007)
    $year_now--;


    else if($month_now <=6 && $year_now > 2007)
    $year_now--;
    }
    else
    {


    if($month_now < date("m") && $year_now <= date("Y"))
    $year_now++;

    else if($month_now > date("m") && $year_now < date("Y"))
    $year_now++;

    }

    $date = getdate(mktime( 0,0,0,$month_no w,1,$year_now)) ;
    }
    else
    {
    $date = getdate();
    }

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

    while (($today <= 32) && ($cont))
    {
    $date_today = getdate(mktime( 0,0,0,$month_nu m,$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"<table width=\"300\" border=\"1\" cellspacing=4 cellpadding=2 style='text-align:center; font-
    size:30.0pt;fon t-family:veranda; style=text-weight:bold; color:#666666'>
    <tr align=center style='font-weight:bold'><t d colspan=\"7\">$ year</td>
    </tr>";

    // begin placement of days according to their
    //beginning weekday

    $day = 1;
    $month = 1;
    $wday = $first_week_day ;
    $firstweek = true;


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

    if ( intval($month_n um) < 10) { $new_month_num = "0$month_nu m"; }
    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 = "$new_day-$new_month_num-$year";


    //$today_year = date("Y");
    $today_year = date("Y");
    $today_month = date("F");
    $today_day = date("j");
    $today_month_nu m = date("m");

    if($day == $today_day && $month_name == $today_month && $year == $today_year)
    $colour = 'yellow';

    else
    $colour = '#FFFCC0';


    $link_date = "$year$new_mont h_num";

    if($day <= $today_day && $new_month_num <= $today_month_nu m && $year == $today_year)
    {
    if (is_file('.\res \Callout\callou t'.$link_date.' .xls'))
    echo "<a href=res\Callou t\callout$link_ date.xls target=\"_blank \"> $month_name
    </a></td>";
    else
    echo "$month_nam e ";
    }
    else if($day > $today_day && $new_month_num < $today_month_nu m && $year <= $today_year)
    {
    if (is_file('.\res \Callout\callou t'.$link_date.' .xls'))
    echo "<a href=res\Callou t\callout$link_ date.xls
    target=\"_blank \"> $month_name </a></td>";
    else
    echo "$month_nam e ";
    }
    else if($new_month_n um >= $today_month_nu m && $year < $today_year)
    {
    if (is_file('.\res \Callout\callou t'.$link_date.' .xls'))
    echo "<a href=res\Callou t\callout$link_ date.xls target=\"_blank \"> $month_name
    </a>";
    else
    echo "$month_nam e ";
    }



    if ($month_name==1 2)
    {
    echo "</tr>\n";
    }

    //$wday++;
    //$wday = $wday % 7;
    $month_name++;
    //}
    echo"

    </table>
    <br>

    ";
    ?>
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Originally posted by Sireen
    What i need is a yearly calender that displays only the months without days .So i can load the data on a monthly basis.

    Parse about any English textual datetime description into a Unix timestamp


    The fastest way to do this is to actually define the month names yourself. It's faster to look up an array index 12 times than to run strtotime 12 times.
    [PHP]
    $monthNames = array(
    1 => 'January',
    2 => 'February',
    etc.
    );

    // isValidMonth checks to make sure $_REQUEST['month'] is set and is a number between 1 and 12.
    $currentMonth = (isValidMonth($ _REQUEST['month'])
    ? $_REQUEST['month']
    : date('n')
    );

    // My first programming teacher would kill me for not using a variable to store the value 13 ('What if they add another month to the calendar?').
    for($i = 1; $i < 13; $i++)
    print((($i == $currentMonth) ? '<b>' : '') . "<a href=\"calendar .php?month=$i\" >{$monthNames[$i]}</a>" . (($i == $currentMonth) ? '</b>' : '') . '<br />');
    [/PHP]

    Comment

    • Sireen
      New Member
      • May 2007
      • 2

      #3
      Originally posted by pbmods
      http://php.net/date
      Parse about any English textual datetime description into a Unix timestamp


      The fastest way to do this is to actually define the month names yourself. It's faster to look up an array index 12 times than to run strtotime 12 times.
      [PHP]
      $monthNames = array(
      1 => 'January',
      2 => 'February',
      etc.
      );

      // isValidMonth checks to make sure $_REQUEST['month'] is set and is a number between 1 and 12.
      $currentMonth = (isValidMonth($ _REQUEST['month'])
      ? $_REQUEST['month']
      : date('n')
      );

      // My first programming teacher would kill me for not using a variable to store the value 13 ('What if they add another month to the calendar?').
      for($i = 1; $i < 13; $i++)
      print((($i == $currentMonth) ? '<b>' : '') . "<a href=\"calendar .php?month=$i\" >{$monthNames[$i]}</a>" . (($i == $currentMonth) ? '</b>' : '') . '<br />');
      [/PHP]

      =============== =============== =


      Thanx alot for answering my question.
      But as I told u i am a very new user in PHP .So if you please tell me how to include the given commands from you to my script & where..

      Comment

      Working...