Jump to content


Photo

CALENDAR TUTORIAL PROBLEM


  • Please log in to reply
17 replies to this topic

#1 davidguz

davidguz
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 03 August 2006 - 06:02 PM

Hi,

  I did the calendar tutorial, and once I upload to the server, it doesn't display the calender at all, only the header tag. What am I doing wrong ???

Here is the link:

http://www.pacificco...ST/calender.php

and here is the php code:

<html>
<head>
<title>PHP CALENDER</title>
<style type="text/css">
<!--
.table.calender { border: 1px solid #000000; border-collapse: collapse; color: #000000; background: #FFFFFF;}
.td.today { border: 1px solid white; color:#000000; background: #EFEFEF; font-weight: bold;}
.td.nomonthdays { border: 1px solid white; color: #000000; background: #EFEFEFEF;}
-->
</style>

</head>

<body>
<h1>PHP CALENDER TUTORIAL</h1>

<?php
error_reporting('0');
ini_set('display_errors', '0');
// Gather variables from
// user input and break them
// down for usage in our script

if (!isset($_REQUEST['date'])){
  $date = mktime(0,0,0,date('m'), date('d'), date('y'));
  } else {
  $date = $_REQUEST['date'];
}
$date = date('d', $date);
$month = date('m', $date);
$year = date('y', $date);
// Get friendly month name
$month_name = date('M', $month_start);
// Fiqure out which day of the week
// the month starts on.
$month_start_day = date('D', $month_start);
switch ($month_start_day){
    case "Sun": $offset = 0; break;
case "Mon": $offset = 1; break;
case "Tue": $offset = 2; break;
case "Wed": $offset = 3; break;
case "Thu": $offset = 4; break;
case "Fri": $offset = 5; break;
case "Sat": $offset = 6; break;
}
// determine how many day are in the last month.
if($month == 1){
  $num_days_last = cal_days_in_month(0, 12 , ($year -1));
} else {
  $num_days_last = cal_days_in_month(0, (month -1), $year); 
}
// determine how many day are in the current month.
$num_day_current = cal_day__in_month(0, $month, $year);
// Build an array for the number of days
// in lsat month.
for($i = 1; $i <= $num_day_last; $i++){
    $num_days_last_array[] = $i;
}
// If the $offset from the starting day of the
// week happens to be Sunday, $offset would be 0,
// so don't need an offset correction.
if($offset > 0){
$offset_correction = array_slice($num_days_last_array, -$offset, $offset);
$new_count = array_merge($offset_correction, $num_days_array);
      $offset_count = count($offset_correction);
}
//The else statement is to prevent building the $offset array.
else {
    $new_count = $num_days_array;
}
// count how many day we have with the two
// previous attays merged together
$current_num = count($new_count);
// Since we will have 5 HTML table rows (TR)
// with 7 table data endries (TD)
// we need to fill in 35 TDs
// so, we will have to fiqure out
// how many days to appended to the end
// of the final array to make it 35 days.
if($current_num > 35) {
  $num_weeks = 6;
  $outset = (42 - $current_num);
} elseif($current_num < 35){
  $num_weeks = 5;
  $outset = (35 - $current_num);
}
if($current_num == 35){
  $num_weeks = 5;
  $outset = 0;
}
// Outset Correction
for($i = 1; $i <= $outset; $i++){
    $new_count[] = $i;
}      
// Now let's "chunk" the $new_count array
// into weeks. Eack week has 7 day
// so we will array_chunk it into 7 days.
$weeks = array_chunk($new_count, 7);
$previous_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=";
if($month == 1){
  $previous_link .= mktime(0,0,0,12,$day,($year -1));
} else {
    $previous_link .= mktime(0,0,0,($month -1),$day,$year);
}
$previous_link .= "\"><< Pre</a>";
 
$next_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=";
if($month == 12){
  $next_link .= mktime(0,0,0,1,$day,($year + 1));
} else {
  $next_link .= mktime(0,0,0,($month +1),$day,$year);
}
$next_link .= "\">Next >></a>";

// Build the heading portion of the calendar table
echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\" width=\"300\" class=\"calendar\">\n".
    "<tr>\n".
"<td> colspan=\"7\">".
"<table align=\"center\">".
"<tr>".
"<td colspan=\"2\" width=\"75\" align=\"left\">$previous_link</td>\n".
"<td colspan=\"3\" width=\"150\" align=\"center\">$month_name $year</td>\n".
"<td colspan=\"2\" with\"75\" align=\"right\">$next_link</td>\n".
"</tr>\n".
"</table>\n".
"</td>\n".
"<table>\n".
"</td>\n".
"<tr>\n".
"<td>S</td> <td>M</td> <td>T</td> <td>W</td> <td>T</td> <td>F</td> <td>S</td>\n".
      "</tr>\n";
 
// Now we break eack key of the array
// into a week and create a new table row for each
// week with the day of that week in the talbe date
$i = 0;
foreach($weeks as $week){
    echo "</tr>\n";
foreach($week as $d){
    if($i < $offset_count){
      $day_link = "<a href\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month -1,$d,$year)."\">$d</a>";
  echo "<td class=\"nomonthdays\">$day_link</td>\n";
}

if($date == mktime(0,0,0,$month,$d,$year)){
    echo "<td class\"today\">$d</td>\n";
} else {

    echo "<td class=\"days\"><a href=\"".$_SERVER['PHP_SELF']."$date=".mktime(0,0,0,$month,$d,$year)."\">$d</td>\n";
}

$day_link = "<a hre=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month +1,$d,$year)."\">$d</a>";
      echo "<td class=\"nomonthdays\">$day_link</td>\n";
}
$i++;

}
echo "</tr>\n";
// Close out your table and that's it!
echo '<tr><td colspan="7" class="day"></td></tr>';
echo '</table>';    
?>



</body>
</html>

And, my email address: superguz2001@yahoo.com


#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 03 August 2006 - 06:10 PM

Please put this into a file and call it "info.php"

<?php

phpinfo();

?>

And let us know when you have so we can check. Also, any idea what the error reporting level is in your php.ini file? Are display errors turned off?
PHP Ninja

#3 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 03 August 2006 - 06:12 PM

Also, comment out these two lines:

<?php

error_reporting('0');
ini_set('display_errors', '0');

?>

PHP Ninja

#4 davidguz

davidguz
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 03 August 2006 - 07:00 PM

Ok, I did what you suggested here is the link:

http://www.pacificco...ST/calender.php

But, I'm interning for this company, so I'm just practicing on their servver, so I don't want to mess with their confiquration, and I don't know if the "error reporting level is in your php.ini file or if the display errors is turned off"

#5 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 03 August 2006 - 07:58 PM

Here is your problem:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /..../public_html/calendar.php on line 141
PHP Ninja

#6 davidguz

davidguz
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 03 August 2006 - 08:33 PM

So, what do I do now?

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 03 August 2006 - 08:36 PM

post the link were you got this totural please thanks.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 davidguz

davidguz
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 03 August 2006 - 08:41 PM

Here is the link:
http://www.pacificco...ST/calender.php

#9 nethnet

nethnet
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts
  • LocationPhiladelphia, PA, USA

Posted 03 August 2006 - 08:44 PM

The PHPFreaks help forums are not to be used for help modifying someone elses code or code obtained from a third-party site.  Please read the guidelines before posting.
"Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep."  --Scott Adams

Current project: nethnet.com

#10 davidguz

davidguz
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 03 August 2006 - 08:44 PM

post the link were you got this totural please thanks.


Sorry, wrong link. I didn't read you post carefully. Here is the correct to the tutorial:
http://www.phpfreaks...orials/83/0.php

#11 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 03 August 2006 - 08:48 PM


fully tested ok copy past ok

<html> 
<head> 
<title>PHP Calendar</title> 
<style type="text/css"> 
<!-- 
.table.calendar {border: 1px solid #000000; border-collapse: collapse; color: #000000; 

background: #FFFFFF; } 
.td.today { border: 1px solid white; color: #000000; background: #EFEFEF; font-weight: bold;} 
.td.monthdays {border: 1px solid #434470; color: #000000; background: #FFFFFFF; } 
.td.nonmonthdays { border: 1px solid white; color: #000000; background: #EFEFEF;} 
--> 
</style> 
<body> 

<?php 
error_reporting('0'); 
ini_set('display_errors', '0'); 
// Gather variables from 
// user input and break them 
// down for usage in our script 

if(!isset($_REQUEST['date'])){ 
   $date = mktime(0,0,0,date('m'), date('d'), date('Y')); 
} else { 
   $date = $_REQUEST['date']; 
} 

$day = date('d', $date); 
$month = date('m', $date); 
$year = date('Y', $date); 

// Get the first day of the month 
$month_start = mktime(0,0,0,$month, 1, $year); 

// Get friendly month name 
$month_name = date('M', $month_start); 

// Figure out which day of the week 
// the month starts on. 
$month_start_day = date('D', $month_start); 

switch($month_start_day){ 
    case "Sun": $offset = 0; break; 
    case "Mon": $offset = 1; break; 
    case "Tue": $offset = 2; break; 
    case "Wed": $offset = 3; break; 
    case "Thu": $offset = 4; break; 
    case "Fri": $offset = 5; break; 
    case "Sat": $offset = 6; break; 
} 

// determine how many days are in the last month. 
if($month == 1){ 
   $num_days_last = cal_days_in_month(0, 12, ($year -1)); 
} else { 
   $num_days_last = cal_days_in_month(0, ($month -1), $year); 
} 
// determine how many days are in the current month. 
$num_days_current = cal_days_in_month(0, $month, $year); 

// Build an array for the current days 
// in the month 
for($i = 1; $i <= $num_days_current; $i++){ 
    $num_days_array[] = $i; 
} 

// Build an array for the number of days 
// in last month 
for($i = 1; $i <= $num_days_last; $i++){ 
    $num_days_last_array[] = $i; 
} 

// If the $offset from the starting day of the 
// week happens to be Sunday, $offset would be 0, 
// so don't need an offset correction. 

if($offset > 0){ 
    $offset_correction = array_slice($num_days_last_array, -$offset, $offset); 
    $new_count = array_merge($offset_correction, $num_days_array); 
    $offset_count = count($offset_correction); 
} 

// The else statement is to prevent building the $offset array. 
else { 
    $offset_count = 0; 
    $new_count = $num_days_array; 
} 

// count how many days we have with the two 
// previous arrays merged together 
$current_num = count($new_count); 

// Since we will have 5 HTML table rows (TR) 
// with 7 table data entries (TD) 
// we need to fill in 35 TDs 
// so, we will have to figure out 
// how many days to appened to the end 
// of the final array to make it 35 days. 


if($current_num > 35){ 
   $num_weeks = 6; 
   $outset = (42 - $current_num); 
} elseif($current_num < 35){ 
   $num_weeks = 5; 
   $outset = (35 - $current_num); 
} 
if($current_num == 35){ 
   $num_weeks = 5; 
   $outset = 0; 
} 
// Outset Correction 
for($i = 1; $i <= $outset; $i++){ 
   $new_count[] = $i; 
} 

// Now let's "chunk" the $all_days array 
// into weeks. Each week has 7 days 
// so we will array_chunk it into 7 days. 
$weeks = array_chunk($new_count, 7); 


// Build Previous and Next Links 
$previous_link = "<a href=\"".$_SERVER['PHP_SELF']."?date="; 
if($month == 1){ 
   $previous_link .= mktime(0,0,0,12,$day,($year -1)); 
} else { 
   $previous_link .= mktime(0,0,0,($month -1),$day,$year); 
} 
$previous_link .= "\"><< Prev</a>"; 

$next_link = "<a href=\"".$_SERVER['PHP_SELF']."?date="; 
if($month == 12){ 
   $next_link .= mktime(0,0,0,1,$day,($year + 1)); 
} else { 
   $next_link .= mktime(0,0,0,($month +1),$day,$year); 
} 
$next_link .= "\">Next >></a>"; 

// Build the heading portion of the calendar table 
echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\" width=\"300\" 

class=\"calendar\">\n". 
     "<tr>\n". 
     "<td colspan=\"7\">\n". 
     "<table align=\"center\">\n". 
     "<tr>\n". 
     "<td colspan=\"2\" width=\"75\" align=\"left\">$previous_link</td>\n". 
     "<td colspan=\"3\" width=\"150\" align=\"center\">$month_name $year</td>\n". 
     "<td colspan=\"2\" width=\"75\" align=\"right\">$next_link</td>\n". 
     "</tr>\n". 
     "</table>\n". 
     "</td>\n". 
     "<tr>\n". 
     "<td>S</td><td>M</td><td>T</td><td>W</td><td>T</td><td>F</td><td>S</td>\n". 
     "</tr>\n"; 

// Now we break each key of the array  
// into a week and create a new table row for each 
// week with the days of that week in the table data 

$i = 0; 
foreach($weeks AS $week){ 
       echo "<tr>\n"; 
       foreach($week as $d){ 
         if($i < $offset_count){ 
             $day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month 

-1,$d,$year)."\">$d</a>"; 
             echo "<td class=\"nonmonthdays\">$day_link</td>\n"; 
         } 
         if(($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset)){ 
            $day_link = "<a 

href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month,$d,$year)."\">$d</a>"; 
           if($date == mktime(0,0,0,$month,$d,$year)){ 
               echo "<td class=\"today\">$d</td>\n"; 
           } else { 
               echo "<td class=\"days\">$day_link</td>\n"; 
           } 
        } elseif(($outset > 0)) { 
            if(($i >= ($num_weeks * 7) - $outset)){ 
               $day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month 

+1,$d,$year)."\">$d</a>"; 
               echo "<td class=\"nonmonthdays\">$day_link</td>\n"; 
           } 
        } 
        $i++; 
      } 
      echo "</tr>\n";    
} 

// Close out your table and that's it! 
echo '<tr><td colspan="7" class="days"> </td></tr>'; 
echo '</table>'; 
?> 
</body> 
</html> 

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#12 davidguz

davidguz
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 03 August 2006 - 08:49 PM

post the link were you got this totural please thanks.


I'm just a beginner at this, and I would like to practice on the scripting. so that's why I'm doing the tutorials on this site to gain some understanding.

Sorry, wrong link. I didn't read you post carefully. Here is the correct to the tutorial:
http://www.phpfreaks...orials/83/0.php



#13 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 03 August 2006 - 08:51 PM

copy and past ok then learn the php staements ok
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#14 nethnet

nethnet
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts
  • LocationPhiladelphia, PA, USA

Posted 03 August 2006 - 08:51 PM

I'm just a beginner at this, and I would like to practice on the scripting. so that's why I'm doing the tutorials on this site to gain some understanding.


There is a special forum for help with PHPFreaks tutorials as well as a Third-Party Scripts forum.  All of this is outlined in the guidelines.
"Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep."  --Scott Adams

Current project: nethnet.com

#15 davidguz

davidguz
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 03 August 2006 - 08:54 PM

Can you direct me to that area?

#16 nethnet

nethnet
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts
  • LocationPhiladelphia, PA, USA

Posted 03 August 2006 - 08:57 PM

All of the PHP forums can be accessed by cliking the "PHP and MySQL" section on the main page of the forums.
"Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep."  --Scott Adams

Current project: nethnet.com

#17 davidguz

davidguz
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 03 August 2006 - 09:59 PM

Well, I'm going to take a break from this, been at it all day, and I still don't see the calendar, anyways I took it down, so it wont display. Anyways, here is my other question before I leave. In order for me to have this work, I have to install php.ini and where do I install at in my machine or the server? Like I said I'm totally new at this, and if I can have someone guide me thru this, I would greatly appreciate it! Anyways, thanks guys for trying to help me out with this, you guys ROCK! Now, off to my Kung-Fu lesson.

#18 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 03 August 2006 - 10:57 PM

There is already a php.ini file on your server. That is the file that has all your php settings. Your particular one is in "/private/etc/php.ini". Unless you have root access, you will not be able to modify it.
PHP Ninja




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users