Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

$_SERVER['PHP_SELF'] link

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

$_SERVER['PHP_SELF'] link

Postby tomboy12 » Tue Jul 08, 2003 4:13 am

I run win xp, apache 1.3 and php 4.3.2. I made a calendar which works fine but the links to next and previous month.

I dont get any errors, it just doesnt work. it looks right in the url as well. eg: month=2&year=2003, when trying to move from january to february.

here is some of the code:

Code: Select all
<?php
function pc_calendar($month, $year, $opts = '') {
   //set default options  //
   if (! is_array($opts)) {
       $opts = array();
   }
   if (! isset($opts['today_color'])) {
      $opts['today_color'] = '#FFFFoo';
   }
   if (! isset($opts['month_link'])) {
      $opts['month_link'] =
      '<a href="'.$_SERVER['PHP_SELF'].'?month=%d&year=%d">%s</a>';
   print '"'.$_SERVER['PHP_SELF'].'?month=%d&year=%d">%s';
   }

   list($this_month,$this_year,$this_day) = split(',',strftime('%m,%y,%d'));
   $day_highlight = (($this_month == $month) && ($this_year == $year));
   
   list($prev_month,$prev_year) =
      split(',',strftime('%m,%Y',mktime(0,0,0,$month-1,1,$year)));
   $prev_month_link = sprintf($opts['month_link'],$prev_month,$prev_year,'&');
   
   list($next_month,$next_year) =
      split(',',strftime('%m,%Y',mktime(0,0,0,$month+1,1,$year)));
   $next_month_link = sprintf($opts['month_link'],$next_month,$next_year,'&');



?>
<form name="form1" method="post" action="index.php">
<table border="0" cellspacing="0" cellpadding="2" align="center">
      <tr>
         <td align="left"><font size="5">
            <?php print $prev_month_link ?>
         </font></td>
         <td colspan="5" align="center"><font size="5">
            <?php print strftime('%B %Y',mktime(0,0,0,$month,1,$year)); ?>
         </font></td>
         <td align="right"><font size="5">
            <?php print $next_month_link ?>
         </font></td>
      </tr>
  <?php


thanks for your help
tomboy12
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Jul 08, 2003 3:54 am

Postby Oleg Butuzov » Tue Jul 08, 2003 5:33 am

this is script that i use in my site you can see and modify like you want...

Code: Select all
<center><br>
<table width="160" border="0" cellspacing="1" cellpadding="1">
<tr>
<td bgcolor="#666666"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF">
<?
$DayInMonth = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$WeekDays = array("","Mo","Tu","We","Tr","Fr","St","Sd");

$SetupColumns = "<td align=center";


if(isset($_GET['date']) && ereg ("([0-9]{1,2})-([0-9]{1,2})-([0-9]{1,2})", $_GET['date']))
{
$currentsday=explode("-", $_GET['date']);
$NumberFirstDay = date("w",mktime(0,0,0,date("$currentsday[1]"),1,date("$currentsday[0]")));
$CurMonth = date("m",mktime(0,0,0,date("$currentsday[1]"),1,date("$currentsday[0]")));
$CurYear = date("Y",mktime(0,0,0,date("$currentsday[1]"),1,date("$currentsday[0]")));
} else {
$NumberFirstDay = date("w",mktime(0,0,0,date("m"),1,date("Y")));
$CurMonth = date("m",mktime(0,0,0,date("m"),1,date("Y")));
$CurYear = date("Y",mktime(0,0,0,date("m"),1,date("Y")));
}




$CurMonth_0=$CurMonth-1;
$CurMonth_1=$CurMonth+1;

$ExMonthe=date("Y-m-d",mktime(0,0,0,date("$CurMonth_0"),1,date("$CurYear")));
$NextMonthe=date("Y-m-d",mktime(0,0,0,date("$CurMonth_1"),1,date("$CurYear")));


if ($CurMonth == "01" ){ $CurMontheRu="January"; }
if ($CurMonth == "02" ){ $CurMontheRu="February"; }
if ($CurMonth == "03" ){ $CurMontheRu="March"; }
if ($CurMonth == "04" ){ $CurMontheRu="April"; }
if ($CurMonth == "05" ){ $CurMontheRu="May"; }
if ($CurMonth == "06" ){ $CurMontheRu="June"; }
if ($CurMonth == "07" ){ $CurMontheRu="Jule"; }
if ($CurMonth == "08" ){ $CurMontheRu="August"; }
if ($CurMonth == "09" ){ $CurMontheRu="September"; }
if ($CurMonth == "10" ){ $CurMontheRu="October"; }
if ($CurMonth == "11" ){ $CurMontheRu="November"; }
if ($CurMonth == "12" ){ $CurMontheRu="December"; }




echo "<table width=100% border=0 class=calendar cellspacing=1 >";
echo "<tr class=cell><td align=left width=20><a href=index.php?date=$ExMonthe><img border=0 src=img/back.gif></a></td><td><center><b>$CurMontheRu</b></center></td><td align=right width=20><a href=index.php?date=$NextMonthe><img border=0 src=img/forward.gif></td></tr>";
echo "</table>";





if ( ($DayInMonth[1] % 4) == 0 ) $DayInMonth[1] = 29;
$j = 1;
if ($NumberFirstDay == 0) $NumberFirstDay = 7;

echo "<table width=100% border=0 cellspacing=1 class=calendar><tr>";
for ($i = 1; $i <= 7; $i++) {
  echo "<td align=center class=cell><b>";
  if (($i == 7) || ($i == 6)) {echo "<font color=#FF6600>$WeekDays[$i]</font>";
    } else { echo "$WeekDays[$i]";
    }
  echo "</td>";
}
echo "</tr><tr>";


#Äëÿ ïðîïóñêà äíåé êîòîðûå ïðåäøåñòâóþò ïåðâîìó äíþ ìåñÿöà
while ($j < $NumberFirstDay) {
   echo "<td></td>";
   $j++;
  }

for ($i = 1; $i <= $DayInMonth[date("m") - 1]; $i++)  {
  if ($j == 0) echo "<tr>\n";
  echo $SetupColumns;
 
  ##
  ##
         $QDa="$CurYear-$CurMonth-$i";
       $DateQuerySec=mysql_query("SELECT * FROM `netlog` WHERE `d_f`='$QDa'");
       if (mysql_num_rows($DateQuerySec) != 0)
       {
       echo " class=cell2>";
       } else {
       echo " class=cell1>";
       }
 
  ##
  ##
 
   
   if (($j == 7)||($j == 6))
      {

        ## Çàïðîñ íà âûáîð çàïèñåé çà ýòè äíè...
      ## åñëè åñòü òî ãóä
      ## åñëè íåò, òî ïîõóþ...
        ## íà÷àëî çàïðîñîâ
        ##
         $QD="$CurYear-$CurMonth-$i";
       $DateQuery=mysql_query("SELECT * FROM `netlog` WHERE `d_f`='$QD'");
       if (mysql_num_rows($DateQuery) != 0)
       {
       $curlink_b="<a href=index.php?date=$QD class=dayv><b>";
       $curlink_e="</b></a>";
       } else {
       $curlink_b="";
       $curlink_e="";
       }

        ##
        ## êîíåö.

      echo "$curlink_b$i$curlink_e";
      }else{

        ## Çàïðîñ íà âûáîð çàïèñåé çà ýòè äíè...
      ## åñëè åñòü òî ãóä
      ## åñëè íåò, òî ïîõóþ...
        ## íà÷àëî çàïðîñîâ
        ##
         $QD="$CurYear-$CurMonth-$i";
       $DateQuery=mysql_query("SELECT * FROM `netlog` WHERE `d_f`='$QD'");
       if (mysql_num_rows($DateQuery) != 0)
       {
       $curlink_b="<a href=index.php?date=$QD class=dayb>";
       $curlink_e="</a>";
       } else {
       $curlink_b="";
       $curlink_e="";
       }

        ##
        ## êîíåö.

      echo "$curlink_b$i$curlink_e";
      }


   if ($i == date("d"));
      echo "</td>\n";


  if ($j == 7) {
      echo "</tr>"; $j=1;
    } else {$j++;}
}

echo "</table>";

$CurYear_1=$CurYear-1;
$CurYear_0=$CurYear+1;
echo "<table width=100% border=0 class=calendar cellspacing=1>";
echo "<tr class=cell><td align=left width=20><a href=index.php?date=$CurYear_1-$CurMonth-01><img border=0 src=img/back.gif></a></td><td><div align=center class=calendar><b>$CurYear</b></div></td><td align=right width=20><a href=index.php?date=$CurYear_0-$CurMonth-01><img border=0 src=img/forward.gif></td></tr>";
echo "</table>";

?></td>
</tr>
</table></td>
</tr>
</table>
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.