Модераторы: skyboy, MoLeX, Aliance, ksnk
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Реализовать логику календаря 
:(
    Опции темы
bulat01
Дата 23.7.2011, 11:42 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 100
Регистрация: 26.10.2010

Репутация: нет
Всего: 0



Здравствуйте всем,
пожалуйста помогите реализовать логику календаря

Код

print "<center><h1>$this_month $this_year</h1>Go to <a href=\"calendar.php?month=$othermonth\">[$otherpage]</a>";


при нажатии Go Next Menth - он должен показывать следующий месяц август - а у меня получается без изменений.
и переменная 'month' не меняется на 1, а остается равное 0. Так в чем может быть проблема?

Помогите.

вот код:

Код

<?php

if ($month == "" | $month < 1) {
   $month = 0; 
   $othermonth = 1; 
}
else {  
   $month = 1; 
   $othermonth = 0;    

 
if ($month == 0) { 
    $thispage = "this month"; 
    $otherpage = "next month"; 
}
else { 
    $thispage = "next month"; 
    $otherpage = "this month"; 
}


$date_time_array = getdate(time());
    $this_month = $date_time_array["month"];
    $this_year  = $date_time_array["year"];
    $this_mon   = $date_time_array["mon"];

if ($month==1){  
    $next_month_stamp = mktime(1,1,1,$this_mon + 1,1,$this_year);
    $date_time_array = getdate($next_month_stamp);
    $this_month = $date_time_array["month"];
    $this_year  = $date_time_array["year"];
    $this_mon   = $date_time_array["mon"];
}
    
    print "<center><h1>$this_month $this_year</h1>Go to <a href=\"calendar.php?month=$othermonth\">[$otherpage]</a>";
    
    echo "<br>";
    echo "Month var: " .$month;
    
    $first_day_stamp = mktime(0,0,0,$this_mon,1,$this_year);    
    $date_time_array = getdate($first_day_stamp);                
    $firstwkday = $date_time_array["wday"] + 1;                

    // find the total days of the month. figure last day of a month as: last day of this month = day zero of next month 
    $last_day_stamp = mktime(0,0,0,$this_mon + 1,0,$this_year);
    $date_time_array = getdate( $last_day_stamp );
    $daysinmonth = $date_time_array["mday"];


 print "<P><table align=center border=1>   
 <tr>
 <th>Sun</th>
 <th>Mon</th>
 <th>Tue</th>
 <th>Wed</th>
 <th>Thu</th>
 <th>Fri</th>
 <th>Sat</th>
 </tr>";

 $date=1;    // months are either 5 or 6 weeks, but 3 weeks if Apr 1 is a Sunday doesn't happen often.
 $maxwk = 5;
 if (($firstwkday + $daysinmonth -1) > 35) { 
    $maxwk = 6 ;
  }

//echo "<br>";
//$array[]=$daysinmonth;
//$array = array("size" => "XL", "color" => "gold");
//print_r(array_values($array));
//echo "<br>";

 for ($week=1; $week <= $maxwk; $week++) { //6 weeks
    // the newlines are just for page weeks formatting 
    
    echo "<tr>\n";
    for($wkday=1; $wkday <=7; $wkday++) { //7 days
     if( ($week>1) || ($wkday>=$firstwkday) ){
       print "<td height=30px width=30px align=\"center\">";
       if ($date <= $daysinmonth) {
         if ($date < 10) {
           print " ";
         }     
            $events = range (1, $daysinmonth);
            
        if (in_array("$date", $events)) { 
           $this_mon = date("m");
          
           print "<a href=\"eventlist.php?year=$this_year&mon=$this_mon&date=$date\">$date</a>";
           
        }     
        else {      
           print $date;
        }  
        
        //added by BMHJ for test
        //print $date;   
        
        echo " ";
         $date++;
       }       
       else {            
         echo "-- ";
       }                
       echo "</td>\n";
     }           
     else {              
       print "<td height=30px width=30px align=\"center\">-- ";
       echo "</td>\n";
     }                
   }         
   echo "</tr>\n";
 }           
 print "</table></center>";
 ?>

PM MAIL   Вверх
Muerto
Дата 23.7.2011, 11:54 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
***


Профиль
Группа: Завсегдатай
Сообщений: 1207
Регистрация: 23.9.2006

Репутация: 3
Всего: 4



А как получиться если слова $_GET['month'] нету в коде  smile 

Вот начало...
Код

<?php
$month=isset($_GET['month'])?(int)$_GET['month']:0;
if ($month == "" | $month < 1) {
   $month = 0; 
   $othermonth = 1; 
}
else {  
   $month = 1; 
   $othermonth = 0;    

 
if ($month == 0) { 
    $thispage = "this month"; 
    $otherpage = "next month"; 
}
else { 
    $thispage = "next month"; 
    $otherpage = "this month"; 
}
$date_time_array = getdate(time());
    $this_month = $date_time_array["month"];
    $this_year  = $date_time_array["year"];
    $this_mon   = $date_time_array["mon"];
if ($month==1){  
    $next_month_stamp = mktime(1,1,1,$this_mon + 1,1,$this_year);
    $date_time_array = getdate($next_month_stamp);
    $this_month = $date_time_array["month"];
    $this_year  = $date_time_array["year"];
    $this_mon   = $date_time_array["mon"];
}
    
    print "<center><h1>$this_month $this_year</h1>Go to <a href=\"calendar.php?month=".(intval($_GET['month'])+1)."\">[$otherpage]</a>";
    
    echo "<br>";
    echo "Month var: " .$month;
    
    $first_day_stamp = mktime(0,0,0,$this_mon,1,$this_year);    
    $date_time_array = getdate($first_day_stamp);                
    $firstwkday = $date_time_array["wday"] + 1;                
    // find the total days of the month. figure last day of a month as: last day of this month = day zero of next month 
    $last_day_stamp = mktime(0,0,0,$this_mon + 1,0,$this_year);
    $date_time_array = getdate( $last_day_stamp );
    $daysinmonth = $date_time_array["mday"];
 print "<P><table align=center border=1>   
 <tr>
 <th>Sun</th>
 <th>Mon</th>
 <th>Tue</th>
 <th>Wed</th>
 <th>Thu</th>
 <th>Fri</th>
 <th>Sat</th>
 </tr>";
 $date=1;    // months are either 5 or 6 weeks, but 3 weeks if Apr 1 is a Sunday doesn't happen often.
 $maxwk = 5;
 if (($firstwkday + $daysinmonth -1) > 35) { 
    $maxwk = 6 ;
  }
//echo "<br>";
//$array[]=$daysinmonth;
//$array = array("size" => "XL", "color" => "gold");
//print_r(array_values($array));
//echo "<br>";
 for ($week=1; $week <= $maxwk; $week++) { //6 weeks
    // the newlines are just for page weeks formatting 
    
    echo "<tr>\n";
    for($wkday=1; $wkday <=7; $wkday++) { //7 days
     if( ($week>1) || ($wkday>=$firstwkday) ){
       print "<td height=30px width=30px align=\"center\">";
       if ($date <= $daysinmonth) {
         if ($date < 10) {
           print " ";
         }     
            $events = range (1, $daysinmonth);
            
        if (in_array("$date", $events)) { 
           $this_mon = date("m");
          
           print "<a href=\"eventlist.php?year=$this_year&mon=$this_mon&date=$date\">$date</a>";
           
        }     
        else {      
           print $date;
        }  
        
        //added by BMHJ for test
        //print $date;   
        
        echo " ";
         $date++;
       }       
       else {            
         echo "-- ";
       }                
       echo "</td>\n";
     }           
     else {              
       print "<td height=30px width=30px align=\"center\">-- ";
       echo "</td>\n";
     }                
   }         
   echo "</tr>\n";
 }           
 print "</table></center>";



А вообще лучше такое на javascript делать

Это сообщение отредактировал(а) Muerto - 23.7.2011, 12:00


--------------------
user posted image
PM MAIL   Вверх
bulat01
Дата 23.7.2011, 12:34 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 100
Регистрация: 26.10.2010

Репутация: нет
Всего: 0



Спасибо большое Muerto. Заработало.
Molte grazie!!!
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "PHP"
Aliance
IZ@TOP
skyboy
SamDark
MoLeX

Новичкам:

  • PHP редакторы собираются и обсуждаются здесь
  • Электронные книги по PHP, документацию можно найти здесь
  • Интерпретатор PHP, полную документацию можно скачать на PHP.NET

Важно:

  • Не брезгуйте пользоваться тегами [code=php]КОД[/code] для повышения читабельности текста/кода.
  • Перед созданием новой темы воспользуйтесь поиском и загляните в FAQ
  • Действия модераторов можно обсудить здесь

Внимание:

  • Темы "ищу скрипт", "подскажите скрипт" и т.п. будут переноситься в форум "Web-технологии"
  • Темы с именами: "Срочно", "помогите", "не знаю как делать" будут УДАЛЯТЬСЯ

Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, IZ@TOP, skyboy, SamDark, MoLeX, awers.

 
1 Пользователей читают эту тему (1 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | PHP: Общие вопросы | Следующая тема »


 




[ Время генерации скрипта: 0.1057 ]   [ Использовано запросов: 21 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.