开发者

My calender has something wrong with the current day and events

How are you all my friends, after a very hard time I got this calender but there was things I can't resolve it down there. please I need some one to tell me whats wrong with this code as there is something wrong with the current day it should have a different color and the same with the events if there is any and the last thing is the when I call the event it get error

here is the code

> <!DOCTYPE html PUBLIC "-//W3C//DTD
> XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html
> xmlns="http://www.w3.org/1999/xhtml">
> <head> <meta http-equiv="Content-Type"
> content="text/html; charset=utf-8" />
> <title>calender</title> <link
> href="styles.css" rel="stylesheet"
> type="text/css" />
> 
>       <script language="javascript">
>         
>               function goLastMonth(month, year) {
>                   
>                       if (month==1){
>                           
>                           --year;
>                           
>                           month = 13;
>                           
>                           }
>                           --month
>                   var monthstring = ""+month+"";
>                   var monthlength = monthstring.length;
>                   if (monthlength <= 1){
>                       
>                           monthstring = "0"+monthstring;
>                       
>                       }
>                        
>                   document.location.href="<?php $_SERVER['PHP_SELF'];
> ?>?month="+monthstring+"&year="+year;
>                   }
>                   
>                   
>                   
>               function goNextMonth(month, year) {
>                   
>                       if (month==12) {
>                           
>                           ++year;
>                           
>                           month = 0;
>                           
>                           }
>                           
>                           ++month
>                   var monthstring = ""+month+"";
>                   var monthlength = monthstring.length;开发者_高级运维
>                   if (monthlength <= 1){
>                       
>                           monthstring = "0"+monthstring;
>                       
>                       }
> 
>                   document.location.href="<?php $_SERVER['PHP_SELF'];
> ?>?month="+monthstring+"&year="+year;
>                   }
>         
>         </script>
> 
> </head>
> 
> <body>
> 
>       <?php 
>               include ("includes/config.php"); 
>               if (isset($_GET['days'])) {
>                       $days = $_GET['days'];
>                       }else{      $days = date("j");          }
>                   if (isset($_GET['month'])) {
>                       $month = $_GET['month'];
>                       }else{      $month = date("m");             }
>                   if (isset($_GET['year'])) {
>                       $year = $_GET['year'];
>                       }else{      $year = date("Y");          }
>                   $currentTimeStamp = strtotime("$year-$month-$days");
>       $monthName = date("F",
> $currentTimeStamp);       $numDay =
> date("t", $currentTimeStamp);
>       $counter = 0;
>               ?>
>         
>         <?php
>               if (isset($_GET['add'])){
>           
>               $eventTitle = $_POST['eventTitle'];
>               $eventDetails = $_POST['eventDetails'];
>               
>               $eventDate = $month."/".$days."/".$year;
>               
>               $inserEvent = "insert into eventCalender (title, details,
> eventDate, deteAdded) values
> ('".$eventTitle."',
> '".$eventDetails."',
> '".$eventDate."',now())";
>               
>               $result = $db -> query ($inserEvent) or die ("$db->error");
>               
>               if (isset($result)) {
>                   
>                       echo "Event added successfully... $eventTitle";
>                   
>                   }else{
>                       
>                       echo "Event Faild to add";
>                       
>                       }
>                       }
>               ?>
> 
> 
>       <table width="291" border="1">  
> <tr>
>     <td width="35" align="left"><input type='button' value='<'
> onclick='goLastMonth(<?php echo
> $month.",".$year ?>);'
> name='previousbutton' ></td>
>     <td colspan="5" id="calenderHader"><?php echo
> $monthName . "&nbsp;" . $year ?></td>
>     <td width="35" align="right"><input type='button'
> value='>' onclick='goNextMonth(<?php
> echo $month.",".$year ?>);'
> name='nextbutton' ></td>   </tr>  
> <tr>
>     <td width="35" align="center" valign="middle">Sun</td>
>     <td width="35" align="center" valign="middle">Mon</td>
>     <td width="35" align="center" valign="middle">Tue</td>
>     <td width="35" align="center" valign="middle">Wed</td>
>     <td width="35" align="center" valign="middle">Thu</td>
>     <td width="35" align="center" valign="middle">Fri</td>
>     <td width="35" align="center" valign="middle">Sat</td>   </tr>
>       <?php       echo "<tr>";        for ($i = 1; $i < $numDay+1; $i++, $counter++) {
>           
>               $timeStamp = strtotime("$year-$month-$i");
>               
>               if ($i==1){
>                   
>                   $fristDay = date ("w", $timeStamp);
>                   
>                   for ($j = 0; $j < $fristDay; $j++, $counter++) {
>                       
>                       echo "<td></td>";
>                       
>                       }
>                   
>                   }
>                   
>               if ($counter % 7 == 0) {
>                   
>                   echo "</tr><tr>";
>                   
>                   }
>                   
>                   $monthstring = $month;
>                   $monthlength = strlen($monthstring);
>                   $daystring = $days;
>                   $daylength = strlen($daystring);
>                   
>                   if ($monthlength <= 1) {
>                       
>                           $monthstring = "0".$monthstring;
>                       
>                       }
>                       
>                   if ($daylength <= 1) {
>                       
>                           $daystring = "0".$daystring;
>                       
>                       }
>                       
>                   $todaysDate = date("m/d/Y");
>                   $dateToCompare = $monthstring . '/' . $daystring . '/' . $year;
>                       
>                       echo "<td align='center' ";
>                   
>                   if ($todaysDate == $dateToCompare){
>                       
>                       echo "class='today'";
>                       
>                       }else{
>                           
>                           $sqlCount = "select * from eventCalender where eventDate=
> '".$dateToCompare."'";
>                           $result_q = $db->query($sqlCount) or die
> ($db->error);
>                           
>                               if ($result_q -> num_rows >= 1){
>                                   
>                                       echo "class='event'";
>                                   
>                                   }
>                           
>                           }
>                       
>                       echo "><a href='".$_SERVER['PHP_SELF']."?month=".$monthstring."&days
> =".$daystring."&year= ".$year."&v=true'>".$i."</a>"."</td>";
> 
>                       }       ?>
>     </tr> </table>
> 
>       <?php   
>       
>               if(isset($_GET['v'])) {
>                   
>                   echo "<a href='".$_SERVER['PHP_SELF']."?month=".$month."&days
> =".$days."&year= ".$year."&v=true &f=true'>Add Event</a>";
>                       
>               if (isset($_GET['f'])){
>                   
>                       include "eventForm.php";
>                       
>                   }
>                   
>                   $myEvents = "select * from eventCalender where
> eventDate='".$month."/".$days."/".$year."'";
>                   $resultEvents = $db->query($myEvents)or
> die($db->error);
>                   
>                   if ($resultEvents) {
>                       
>                           while ($event = $resultEvents) {
>                               
>                                   echo "Title : " . $event->title  . "<br />" ;
>                                   echo "Event : " . $event->details . "<br />" ;
>                               
>                               }
>                       
>                       }
>                   
>                   }
>               ?>
> 
> </body> </html>


first of all thanks for the good answers that I got, it was really very helpful for me

this is the last code I have put it for this calender.

    <?php               

    include ("includes/config.php");?>   

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>calender</title> <link href="styles.css" rel="stylesheet" type="text/css" />

        <script language="javascript">

                function goLastMonth(month, year) {

                        if (month==1){

                            --year;

                            month = 13;

                            }
                            --month
                    var monthstring = ""+month+"";
                    var monthlength = monthstring.length;
                    if (monthlength <= 1){

                            monthstring = "0"+monthstring;

                        }

                    document.location.href="<?php $_SERVER['PHP_SELF']; ?>?month="+monthstring+"&year="+year;
                    }



                function goNextMonth(month, year) {

                        if (month==12) {

                            ++year;

                            month = 0;

                            }

                            ++month
                    var monthstring =""+month+"";
                    var monthlength =monthstring.length;
                    if (monthlength <= 1){

                            monthstring ="0"+monthstring;

                        }

                    document.location.href="<?php $_SERVER['PHP_SELF']; ?>?month="+monthstring+"&year="+year;
                    }

        </script>

</head>

<body>

        <?php 

        if (isset($_GET['days'])) {
                        $days = $_GET['days'];
                        }else{      $days = date("j");          }
                    if (isset($_GET['month'])) {
                        $month = $_GET['month'];
                        }else{      $month = date("m");             }
                    if (isset($_GET['year'])) {
                        $year = $_GET['year'];
                        }else{      $year = date("Y");          }
                    $currentTimeStamp = strtotime("$year-$month-$days");        $monthName = date("F", $currentTimeStamp);      $numDay = date("t", $currentTimeStamp);         $counter = 0;
                ?>

        <?php
                if (isset($_GET['add'])){

                $eventTitle = $_POST['eventTitle'];
                $eventDetails = $_POST['eventDetails'];

                $eventDate = $month."/".$days."/".$year;

                $inserEvent = "insert into eventCalender (id, title, details, eventDate, deteAdded) values ('', '".$eventTitle."', '".$eventDetails."', '".$eventDate."', 'now()')";

                $result = $db -> query ($inserEvent) or die ("$db->error");

                if (isset($result)) {

                        echo "Event added successfully... $eventTitle";

                    }else{

                        echo "Event Faild to add";

                        }
                        }
                ?>


        <table width="291" border="1">   <tr>
    <td width="35" align="left"><input type='button' value='<' onclick='goLastMonth(<?php echo $month.",".$year ?>);' name='previousbutton' ></td>
    <td colspan="5" id="calenderHader"><?php echo $monthName . "&nbsp;" . $year ?></td>
    <td width="35" align="right"><input type='button' value='>' onclick='goNextMonth(<?php echo $month.",".$year ?>);' name='nextbutton' ></td>   </tr>   <tr>
    <td width="35" align="center" valign="middle">Sun</td>
    <td width="35" align="center" valign="middle">Mon</td>
    <td width="35" align="center" valign="middle">Tue</td>
    <td width="35" align="center" valign="middle">Wed</td>
    <td width="35" align="center" valign="middle">Thu</td>
    <td width="35" align="center" valign="middle">Fri</td>
    <td width="35" align="center" valign="middle">Sat</td>   </tr>
        <?php       echo "<tr>";        for ($i = 1; $i < $numDay+1; $i++, $counter++) {

                $timeStamp = strtotime("$year-$month-$i");

                if ($i==1){

                    $fristDay = date ("w", $timeStamp);

                    for ($j = 0; $j < $fristDay; $j++, $counter++) {

                        echo "<td></td>";

                        }

                    }

                if ($counter % 7 == 0) {

                    echo "</tr><tr>";

                    }

                    $monthstring = $month;
                    $monthlength = strlen($monthstring);
                    $daystring = $days;
                    $daylength = strlen($daystring);

                    if ($monthlength <= 1) {

                            $monthstring = "0".$monthstring;

                        }

                    if ($daylength <= 1) {

                            $daystring = "0".$daystring;

                        }

                    $todaysDate = date("m/d/Y");
                    $dateToCompare = $monthstring.'/'.$daystring.'/'.$year;

                        echo "<td align='center' ";

                    if ($todaysDate == $dateToCompare){

                        echo "class='today'";

                        }else{

                            $sqlCount = "select * from eventCalender where eventDate= '".$dateToCompare."'";
                            $result_q = $db->query($sqlCount) or die ($db->error);

                                if ($result_q -> num_rows >= 1){

                                        echo "class='event'";

                                    }

                            }

                        echo "><a href='".$_SERVER['PHP_SELF']."?month=".$monthstring."&days=".$daystring."&year=".$year."&v='true'>".$i."</a>"."</td>";

                        }       ?>
    </tr> </table>

        <?php
                $myEvents = "select * from eventCalender where eventDate='".$month."/".$days."/".$year."'";         $resultEvents = $db->query($myEvents)or die($db->error);
                if ($resultEvents -> num_rows>=1) {

                            while ($event = $resultEvents ->fetch_object()) {

                                    echo "Title : " . $event->title  . "<br />" ;
                                    echo "Event : " . $event->details . "<br />" ;

                                }

                        }

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

                    echo "<a href='".

> Blockquote

$_SERVER['PHP_SELF']."?month=".$month."&days=".$days."&year=".$year."&v=true&f=true'>Add Event</a>";

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

                        include "eventForm.php";

                       }
                    }
                ?>

</body> </html>

I am sure there is still some bugs that I should take care of but now it's working

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜