SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying events in a calendar

    I have a calendar that shows the days of the month and can be navigated from one month to the next. What I would like to do is take events that are stored and display them in the appropriate calendar date block.

    I am not sure what portion of the code someone might need to see but I have included the loop that lays out the dates on the table:
    PHP Code:
    foreach($weeks AS $week) {
            echo 
    "<tr>\n";
            
            foreach(
    $week as $d) {
                
                if(
    $i $offset_count) {
                    
    $day_link "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,($month 1),$d,$year)."\">$d</a>";
                    echo 
    "<td class=\"nonmonthdays\">$day_link</td>\n";
                }
                
                if((
    $i >= $offset_count) && ($i < ($num_weeks 7) - $outset)) {
                    if(
    $date == mktime(0,0,0,$month$d$year)) {
                        echo 
    "<td class=\"today\">$d</td>\n";
                    } else {
                        echo 
    "<td class=\"days\"><a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month,$d,$year)."\">$d</a></td>\n";
                    }
                } elseif(
    $i >= ($num_weeks 7) - $outset) {
                    
    $day_link "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month 1,$d,$year)."\">$d</a>";
                    echo 
    "<td class=\"nonmonthdays\">$day_link</td>\n";
                }
                
    //attempt to insert data for parties
                
    while ($row mysql_fetch_array($selectquery)) {
                    
    $party_host_id $row['id'];
                    
    $party_host_name $row['hostname'];
                    
    $party_calendar_entry strtotime($row['partydate']);
                
                
                    if(
    $party_calendar_entry $date) {
                        
    $host_link "<a href=\"party_sign_up.php?id=".$party_host_id."\">".$party_host_name."</a>";
                        echo 
    "td class=\"days\">$host_link</td>\n";
                    }
                }
            
            
    $i++;
            }
            echo 
    "</tr>\n";
        } 
    You can also see the comment where I 'attempt' to load the data that needs to be placed at a particular date on the calendar.

    I am not sure if the data insert for the party should be here or not but if not where should it be moved to?

    Thanks, and again - If anyone needs any further code please let me know.

    Dan

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Almost, except that $selectquery comes from nowhere and you break the table.

    You want to add your events to the same cell of the day so mind the html. Where there is $day_link, append your events to that string.
    Saul

  3. #3
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    Almost, except that $selectquery comes from nowhere and you break the table.

    You want to add your events to the same cell of the day so mind the html. Where there is $day_link, append your events to that string.
    Ahh! That makes sense (now). You are exactly right though, it did break the table. I am assuming that i would put my while statement right after the foreach statement.

    Thanks,

    Dan

  4. #4
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    Almost, except that $selectquery comes from nowhere and you break the table.

    You want to add your events to the same cell of the day so mind the html. Where there is $day_link, append your events to that string.
    So I tried to move the while loop to go through the array of data from the query and what I get is the event listed for everyday of the week, not just the day it should be on.

    I think the while should be where it is but it only returns one result (not two which it should be doing in this instance). I do not know how to set up the if correctly, it creates the link and everything but I do not know why it puts info in everyday of the week

    Here is the updated code:
    PHP Code:
        
        $i 
    0;
        
        
        foreach(
    $weeks AS $week) {
            
            echo 
    "<tr>\n";
            
            while (
    $row mysql_fetch_array($selectquery)) {
                    
                    
    $party_host_id $row['id'];
                    
    $party_host_name $row['hostname'];
                    
    $party_calendar_entry strtotime($row['partydate']);
            
            }
    //while        
                
                
    if($party_calendar_entry $date) {
                        
                        
    $host_link "<a href=\"party_sign_up.php?id=".$party_host_id."\">".$party_host_name."</a>";
                        
    //echo "td class=\"days\">$host_link</td>\n";
                    
                    
    foreach($week as $d) {
                
                        if(
    $i $offset_count) {
                            
    $day_link "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,($month 1),$d,$year)."\">$d</a>";
                            echo 
    "<td class=\"nonmonthdays\">$day_link.$host_link</td>\n";
                        }
                
                        if((
    $i >= $offset_count) && ($i < ($num_weeks 7) - $outset)) {
                            if(
    $date == mktime(0,0,0,$month$d$year)) {
                                echo 
    "<td class=\"today\">$d</td>\n";
                            } else {
                                echo 
    "<td class=\"days\"><a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month,$d,$year)."\">$d</a></td>\n";
                            }
                        
                        } elseif(
    $i >= ($num_weeks 7) - $outset) {
                            
    $day_link "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month 1,$d,$year)."\">$d</a>";
                            echo 
    "<td class=\"nonmonthdays\">$day_link.$host_link</td>\n";
                        }
                    
                    }
    //foreach $week as $d
            
            
                    
    $i++;
                
                }
    //if $party_calendar_entry=$date
                
                
    echo "</tr>\n";
        
        }
    //foreach $weeks as $week 

  5. #5
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Because the comparison operator is ==, not =

    PHP Code:
    if($party_calendar_entry == $date
    Saul

  6. #6
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So I have tried every placement of these loops to get this to work correct and I still cannot figure out where it is supposed to be to give the results that I need.
    PHP Code:
    $i 0;
        
        
        foreach(
    $weeks AS $week) {
            
            echo 
    "<tr>\n";
            
            
                while (
    $row mysql_fetch_array($selectquery)) {
                    
                            
    $party_host_id $row['id'];
                            
    $party_host_name $row['hostname'];
                            
    $party_calendar_entry strtotime($row['partydate']);
                
                    
                    if(
    $party_calendar_entry == $date) {
                        
                        
    $host_link "<a href=\"party_sign_up.php?id=".$party_host_id."\">".$party_host_name."</a>";
                        
    //echo "td class=\"days\">$host_link</td>\n";
                    
    }//if $party_calendar_entry=$date    
                    
                    
                
    }//while    
                    
    foreach($week as $d) {
                        
                        if(
    $i $offset_count) {
                            
    $day_link "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,($month 1),$d,$year)."\">$d</a>";
                            echo 
    "<td class=\"nonmonthdays\">$day_link.$host_link</td>\n";
                        }
                
                        if((
    $i >= $offset_count) && ($i < ($num_weeks 7) - $outset)) {
                            if(
    $date == mktime(0,0,0,$month$d$year)) {
                                echo 
    "<td class=\"today\">$d</td>\n";
                            } else {
                                echo 
    "<td class=\"days\"><a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month,$d,$year)."\">$d</a></td>\n";
                            }
                        
                        } elseif(
    $i >= ($num_weeks 7) - $outset) {
                            
    $day_link "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month 1,$d,$year)."\">$d</a>";
                            echo 
    "<td class=\"nonmonthdays\">$day_link.$host_link</td>\n";
                        }
                    
                    }
    //foreach $week as $d
            
            
                    
    $i++;
                
                
            
            
                echo 
    "</tr>\n";
        
        }
    //foreach $weeks as $week 
    That is the complete code and here are my thoughts on what is happening and what should be happening.

    PHP Code:
    while ($row mysql_fetch_array($selectquery)) {
                    
                            
    $party_host_id $row['id'];
                            
    $party_host_name $row['hostname'];
                            
    $party_calendar_entry strtotime($row['partydate']);
                
                    
                    if(
    $party_calendar_entry == $date) {
                        
                        
    $host_link "<a href=\"party_sign_up.php?id=".$party_host_id."\">".$party_host_name."</a>";
                        
    //echo "td class=\"days\">$host_link</td>\n";
                    
    }//if $party_calendar_entry=$date    
                    
                    
                
    }//while 
    The while loop goes through the data (there are currently 3 records) and for each record it goes through the if statement to see which date should have the $party_host_name listed in it.

    PHP Code:
    foreach($week as $d) {
                        
                        if(
    $i $offset_count) {
                            
    $day_link "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,($month 1),$d,$year)."\">$d</a>";
                            echo 
    "<td class=\"nonmonthdays\">$day_link.$host_link</td>\n";
                        }
                
                        if((
    $i >= $offset_count) && ($i < ($num_weeks 7) - $outset)) {
                            if(
    $date == mktime(0,0,0,$month$d$year)) {
                                echo 
    "<td class=\"today\">$d</td>\n";
                            } else {
                                echo 
    "<td class=\"days\"><a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month,$d,$year)."\">$d</a></td>\n";
                            }
                        
                        } elseif(
    $i >= ($num_weeks 7) - $outset) {
                            
    $day_link "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month 1,$d,$year)."\">$d</a>";
                            echo 
    "<td class=\"nonmonthdays\">$day_link.$host_link</td>\n";
                        }
                    
                    }
    //foreach $week as $d 
    In this set of if statements it looks to append the $host_link to the $day_link. What it should be doing is only doing that on the exact date (I am getting the entire week). I see a problem with my concatenation where if $host_link is blank it still appends a '.' but I think I can do another if...else if based on the value of $host_link.

    Any further ideas?

    Dan

  7. #7
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sometimes there is no need to reinvent the wheel.

    Check out Yahoo's UI Library Calendar Function: http://developer.yahoo.com/yui/calendar/

  8. #8
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In this situation I am having to reinvent the wheel. I have other portions of the database tied around a very simple scheduling tool. The user would like a calendar to go along with it. I have attempted to talk them out of the calendar, not because of the difficulty creating it, but the fact that they will not have any more than 3-4 events per month.

    Thanks,

    Dan

  9. #9
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand that.

    Here is a calendar I made back in the day: http://www.wedeking.org/calendar/, I can provide you with the source if you are interested.

    Just PM me your info.

  10. #10
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not trying to bump this but I was thinking about this last night.

    Would it be better for me to put the results from my select statement into an array outside of the other foreach loops? That way I could go through the array inside the foreach loop and and increment the array with a for loop?

    I am struggling with a solution to this.

    I have looked online at a ton of calendars and through every book I have but it seems I can not find this covered any where.

    Dan


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
  •