Jump to content

capture date on calendar problem


geroido

Recommended Posts

Hi all

I've just downloaded this calendar script after a long long search. It works really nicely. It scans backwards and forwards through the calender years and it came with a style sheet so it looks great. Here's my problem. I havn't studied it closely. As I'm a beginner to PHP, I don't know how to modify it yet. As I say it displays a calendar and the user can go back or forward through the months and years. I need to modify the code so that I can capture the date that the user selects(to trawl through my database for records associated with that date). I would like a text box on the page that fills with the date selected by the user so I can grab it. When I hover over a particular dat date, the date underlines and a little link hand appears leading me to think that I can have some sort of click event maybe. Any ideas

 

 

 

 

<?php

      function calendar($year, $month, $day_offset = 0){

          $days = array("sunday","monday","tuesday","wednesday","thursday","friday","saturday");

          $months = array("january","february","march","april","may","june","july","august","september","october","november","december");

          $day_offset = $day_offset % 7;

          $start_day = gmmktime(0,0,0,$month,1,$year);

          $start_day_number = date("w",$start_day);

          $days_in_month = date("t",$start_day);

         

          $previous_month = ($month-1);

          $previous_year = $year;

          if($previous_month == 0){

            $previous_month = '12';

            $previous_year = ($year-1);

          }

         

          $next_month = ($month+1);

          $next_year = $year;

          if($next_month == '13'){

            $next_month = '1';

            $next_year = ($year+1);

          }

         

          $final_html .= "<ul class=\"calender\"><li><span class=\"nav1\"><a href=\"calendar.php?y=".$previous_year."&m=".$previous_month."\">Back</a></span><span class=\"nav2\">".$months[$month-1]." $year</span><span class=\"nav1\"><a href=\"calendar.php?y=".$next_year."&m=".$next_month."\">Next</a></span></li>\n";

          $final_html .= "<li>";

          for($x=0;$x<=6;$x++){
  
              $final_html .= "<span class=\"nav1\">".$days[($x+$day_offset)%7]."</span>";

          }

          $final_html .= "</li>\n";

         
  
          $final_html .= "</ul><ul class=\"calender2\"><li>\n";

         

         

          $blank_days = $start_day_number - $day_offset;
  
          if($blank_days<0){$blank_days = 7-abs($blank_days);}
  
          for($x=0;$x<$blank_days;$x++){
  
              $final_html .= "<span class=\"nav1\"> </span>";

          }

          for($x=1;$x<=$days_in_month;$x++){

              if(($x+$blank_days-1)%7==0){

                  $final_html .= "</li>\n<li>";
  
              }

              $final_html .= "<span class=\"nav1\"><a href=\"javascript:;\">$x</a></span>";

          }

          while((($days_in_month+$blank_days)%7)!=0){

              $final_html .= "<span class=\"nav1\"> </span>";

              $days_in_month++;

          }

          $final_html .= "</li>\n</ul>";

          return($final_html);

      }

       

      if(isset($_GET['y'])){

          $y = $_GET['y'];

      } else {

          $y = date("Y");

      }

      if(isset($_GET['m'])){

          $m = $_GET['m'];

      } else {

          $m = date("m");

      }

      echo calendar($y,$m);

      ?>
[code]

[/code]

Link to comment
https://forums.phpfreaks.com/topic/118632-capture-date-on-calendar-problem/
Share on other sites

Hi Dyslexicdog

Sorry for delay in reply. Actually now that I think of it, when the user selects 'back' or 'next', it stays on the same page and displays the previous or next month. The actual days are not linked to anything, there is no response when they are clicked. I would like the user to click a day, capture the date and link to another page to scan the database or it can return to the same page again with the database results. As long as I can make the days respond when clicked and capture the date, I can then use the date for database retrieval.

Problem is I know nothing about javascript and just don't have the time right now.

I think I've identified the part of the code which puts the calendar on the page. Can you see the href part below. I think this displays the 'back' and 'forward' links back to the calender.php page. I also think that the final line of code here displays the days. What I need to know is how to attach a href to this and send the date over to another page of my choosing. Any ideas?

 

$final_html .= "<ul class=\"calender\"><li><span class=\"nav1\"><a href=\"calendar.php?y=".$previous_year."&m=".$previous_month."\">Back</a></span><span class=\"nav2\">".$months[$month-1]." $year</span><span class=\"nav1\"><a href=\"calendar.php?y=".$next_year."&m=".$next_month."\">Next</a></span></li>\n";

          $final_html .= "<li>";

          for($x=0;$x<=6;$x++){
  
           [color=red][font=Verdana][font=Verdana] $final_html .= "<span class=\"nav1\">".$days[($x+$day_offset)%7]."</span>";[/font][/font][/color]

 

I'm so close with this one. I've just managed to create a link on every day to a new page when the user clicks it. Now if I can just capture the date chosen and send that to the new page I can then use it to search my database and return records. Do you think that if I include a form tag around it, I can send the date over. The code is below. I included the wrong code last time. the code below generates the days and I've changed it to include a href to the new page(test.php). It's working and going to the new page. I know that the year is stored in a variable called $y and month in $m.

 


$final_html .= "<span class=\"nav1\"><a href=\"test.php\">$x</a></span>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.