Results 1 to 7 of 7

Thread: php calendar

  1. #1
    Join Date
    Apr 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default php calendar

    Hi everyone,

    Nice site, I've been on here already and found myself quite at home.

    I've started to develop a web based calendar for a dragonboating team to help coaches and the captain to inform the rest of the team of up and coming events and races.

    It can be found here: http://tc.sillifish.co.uk

    It is still in the development stage and pretty simple (to some of you hardcore programmers) but I'm proud of what I've done coming from a networking background.

    The coach has requested that only he and a few other have the ability to add events, when users click on events or a calendar date, they can specifiy their availability and produce a list under the event highlighting which users will be attending, which users will not be attending and a total count of each. These features are currently in development (in my mind) and have a rough idea of how these will work.

    I also want to be able to do two things:
    1) Move months
    2) Highlight cells which have events

    With 1) I have no idea where to start
    With 2) I have tried a piece of code (a while statement within a while statement) but the php timout exceeds 30 seconds and fails.

    Rather than using a login form (as these pages will be migrated to another host within Joomla), I have on the home page, users which simulate admin users and regular users.

    Just my luck! I can't remember the ftp details to get samples of the code...

    I'll edit this when I get home and where I can insert parts of the coding...

    Anyways, your thoughts on the website above would be appreciated...

    Thanks

    Nilesh

  2. #2
    Join Date
    Mar 2008
    Posts
    122
    Thanks
    17
    Thanked 5 Times in 5 Posts

    Default

    2) Highlight cells which have events
    I have a rough idea:

    Say you are using a mysql table to store the events,

    When the coach (or whoever) adds an event, you can have a field that updates to 1 i.e 'day_has_event', so then you can check if the 'day_has_event' field has a value of 1, if it does then highlight the cell.

    I hope you understood me lol, anyone care to rewrite this ??

  3. #3
    Join Date
    Mar 2008
    Posts
    122
    Thanks
    17
    Thanked 5 Times in 5 Posts

    Default

    2) Highlight cells which have events
    I have a rough idea:

    Say you are using a mysql table to store the events,

    When the coach (or whoever) adds an event, you can have a field that updates to 1 i.e 'day_has_event', so then you can check if the 'day_has_event' field has a value of 1, if it does then highlight the cell.

    I hope you understood me lol, anyone care to rewrite this ??

  4. #4
    Join Date
    Apr 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi mate,

    Thanks for replying, yeah I understood what you suggested.

    I've managed to get the code for the page:

    PHP Code:
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>SilliFish.co.uk - The Home of The Typhoon Movie Database</title>
    <STYLE TYPE="text/css">
    <!--
    h2{font-family: Verdana, Arial, Helvetica, sans-serif; font-size:12pt;}
    p{font-family: Verdana, Arial, Helvetica, sans-serif; font-size:11px;}
    td{font-family: Verdana, Arial, Helvetica, sans-serif; font-size:11px; }
    th{font-family: Verdana, Arial, Helvetica, sans-serif; font-size:12px; }

    --->
    </STYLE>
    </head>

    <body BGCOLOR="#525252" TEXT="#E68313" LINK="#E68313" VLINK="#E68313">
    <center> 
      <h2>Typhoon Calendar Test<br />
          Typical User View</h2><br/>
      <p><a href="index.php">Calendar Home Page</a></p>
      <p>This will not be how the final layout will look like...</p>
     <?php

    $username
    ="*******";
    $password="*******";
    $database="*******";

    $connection=mysql_connect("localhost""$username""$password") or die(mysql_error());
    mysql_select_db("$database") or die(mysql_error());

    $userresult mysql_query("SELECT * FROM typhoon_user ORDER BY user_id") or die(mysql_error());

    $getuserid=$_GET[detu];

    while(
    $row mysql_fetch_array($userresult))
    {
        
    $listuseradmin=$row['admin'];
        
    $listuserid=$row['user_id'];
        
        if ( 
    $listuserid == $getuserid )
        {
            if ( 
    $listuseradmin == "1" )
            {
                echo 
    "<p>Click <a href='calendaradmin.php?detu=";
                echo 
    urlencode($getuserid);
                echo 
    "'>here</a> to add events to the calendar</p>";
            }else{
            }
        }else{
        }
    }

    $date =time () ;

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

    $first_day mktime(0,0,0,$month1$year) ;

    $title date('F'$first_day) ; 

    $day_of_week date('D'$first_day) ;

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

    $days_in_month cal_days_in_month(0$month$year) ;

    echo 
    "<table border=1 width=294>";
    echo 
    "<tr><th colspan=7>$title $year</th></tr>";
    echo 
    "<tr><td width=42 align=center>S</td><td width=42 align=center>M</td><td width=42 align=center>T</td><td width=42 align=center>W</td><td width=42 align=center>T</td><td width=42 align=center>F</td><td width=42 align=center>S</td></tr>";

    $day_count 1;

    echo 
    "<tr>";

    while ( 
    $blank )
    {
    echo 
    "<td align=center> - </td>";
    $blank $blank-1;
    $day_count++;


    $day_num 1;

    while ( 
    $day_num <= $days_in_month )
    {
        
    //$eventresult = mysql_query("SELECT * FROM typhoon_event ORDER BY date") or die(mysql_error());
        //while($row = mysql_fetch_array($eventresult))
        //{
            //$dateevent = $row['date'];
            //if ( $dateevent == "'$year-$month-$day'" )
            //{
                //echo "<td align=center bgcolor=#74DF00><a href='viewevent.php?detu=$getuserid&pday=$day_num&pmonth=$month&pyear=$year'><b>$day_num</b></a></td>";
            //}else{
                
    if ( $day_num == $day)
                {
                    echo 
    "<td align=center bgcolor=#41383C><a href='viewevent.php?detu=$getuserid&pday=$day_num&pmonth=$month&pyear=$year'><b>$day_num</b></a></td>";
                }else{
                    echo 
    "<td align=center><a href='viewevent.php?detu=$getuserid&pday=$day_num&pmonth=$month&pyear=$year'>$day_num</a></td>";
                }
            
    //}
            
    $day_num++;
            
    $day_count++;

            if (
    $day_count 7)
            {
                echo 
    "</tr><tr>";
                
    $day_count 1;
            }
        
    //}


    while ( 
    $day_count >&& $day_count <=)
    {
    echo 
    "<td> </td>";
    $day_count++;
    }

    echo 
    "</tr></table>";

    mysql_close($connection);
    ?>
    </center>
    </body>
    </html>
    As you can see I tried to add

    PHP Code:
    //$eventresult = mysql_query("SELECT * FROM typhoon_event ORDER BY date") or die(mysql_error());
        //while($row = mysql_fetch_array($eventresult))
        //{
            //$dateevent = $row['date'];
            //if ( $dateevent == "'$year-$month-$day'" )
            //{
                //echo "<td align=center bgcolor=#74DF00><a href='viewevent.php?detu=$getuserid&pday=$day_num&pmonth=$month&pyear=$year'><b>$day_num</b></a></td>";
            //}else{ 
    but this failed...

  5. #5
    Join Date
    Mar 2008
    Posts
    122
    Thanks
    17
    Thanked 5 Times in 5 Posts

    Default

    In your while statement add:

    PHP Code:
    while($row mysql_fetch_array($userresult))

        if(
    $row['day_has_event'] == "1")
            echo 
    "Echo the highlighted cell here";
        else
            echo 
    "Echo the plain cell here";


  6. #6
    Join Date
    Apr 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That will not work. Because of the way I have designed the calendar, the date from the event table (in the format YYYY-MM-DD) should equal the variables $year-$month-$day

  7. #7
    Join Date
    Apr 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    DONE IT!!! WOOHOO!!!

    it was the ordering of the code.... here it is

    PHP Code:
    while ( $day_num <= $days_in_month )
    {
        
    $eventresult mysql_query("SELECT * FROM typhoon_event ORDER BY date") or die(mysql_error());
        while(
    $row mysql_fetch_array($eventresult))
        {
            
    $dateevent $row['date'];
            
            if ( 
    $dateevent == "$year-$month-$day_num)
            {
                echo 
    "<td align=center bgcolor=#74DF00><a href='viewevent.php?detu=$getuserid&pday=$day_num&pmonth=$month&pyear=$year'><b>$day_num</b></a></td>";
                
                
    $day_num++;
                
    $day_count++;
                    
                if (
    $day_count 7)
                {
                    echo 
    "</tr><tr>";
                    
    $day_count 1;
                }
            
                if (
    $day_num >= $days_in_month)
                {
                    break;
                }
            }
        }
        
        if ( 
    $day_num == $day)
        {
            echo 
    "<td align=center bgcolor=#41383C><a href='viewevent.php?detu=$getuserid&pday=$day_num&pmonth=$month&pyear=$year'><b>$day_num</b></a></td>";
        }else{
            echo 
    "<td align=center><a href='viewevent.php?detu=$getuserid&pday=$day_num&pmonth=$month&pyear=$year'>$day_num</a></td>";
        }
        
        
    $day_num++;
        
    $day_count++;

        if (
    $day_count 7)
        {
            echo 
    "</tr><tr>";
            
    $day_count 1;
        }
        
        if (
    $day_num >= $days_in_month)
        {
            break;
        }
        


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •