Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problems with PHP Calendar

    Hi there,

    I'm having trouble with a PHP calendar script I'm trying to create for my new employers. Basically, users enter events via a script and then the calendar dynamically displays the events on the particular date, and provides a link to the full details of the event. However, I'm having trouble getting the calendar to display all the events. I can get it to display one, but I'm having a bit of a mental block in terms of how to get the rest to display. This is where you magical, wonderful, brilliant people swoop in to save the day

    Here is a code segment:

    php:for( $counter = 1; $counter <= $numdaysinmonth; $counter ++ )
    {


    $rowcounter ++;

    if($counter)
    {
    $dayVal = $getEventArray['evtDay'];
    $dayQuery = "SELECT evtName FROM event_table WHERE evtDay = '$dayVal'";
    $dayResult = mysql_query($dayQuery) or die ("Problem with query: " . mysql_query());
    $dayArray = mysql_fetch_array($dayResult) or die ("Problem with fetch: " . mysql_query());
    if($dayVal == $initial)
    {
    $task = $dayArray['evtName'];
    printf("This is a test: %s ", $dayVal);
    }
    elseif($dayVal != $initial)
    {
    $task = "";
    }

    printf("tt<td>%s - %s</td>n", $counter, $task);
    $initial ++;
    next($getEventArray);
    printf("Last DayVal = %s", $getEventArray['dayVal']);
    }
    else
    {
    print("this is the else");
    echo "tt<td>$counter</td>n";
    }
    ?>



    The full code is here: www.andyseaton.co.uk/testCalendar.txt

    and a sample of the working calendar: www.andyseaton.co.uk/testCalendar.php

    Basically, what I want is the counter to increment through the days of the month, and if it hits any of the values in the array (which is taken from the events table) it prints both the day number and the event details.

    so if there were three events from the month of march, on the 12th, 14th and 21st, for example, the array values would be {12, 14, 21} I can get the first one to display, as shown in the calendar just now, but I cannot get it to iterate to the next value in the array. I have tried to use next() and each() but those do not seem to work.

    I would appreciate any light that people could shed on this issue.

    Cheers

    Andy

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,798
    Thanks
    19
    Thanked 156 Times in 147 Posts
    I don;t know exactly how you are getting your days, months, and years, but are you looking for something like this:

    PHP Code:
    $dayArray = array(1,2,3,4,5,6,7,8,9,10,....);

    foreach (
    $dayArray as $val)
    {
        echo 
    "<p><b>$month $val, $year</b>";
        
        
    $query "SELECT evtName FROM event_table WHERE evtDay='$val' AND evtMonth='$month' AND evtYear='$year'";
        
    $result mysql_query($query) or die ("Problem with query: " mysql_query());
        if (
    mysql_num_rows($result) >= 1)
        {
            while (
    $row mysql_fetch_assoc($result))
            {    
                echo 
    "<br />".$row['evtName'];
            {
        }
        
        echo 
    "</p>";

    Last edited by chump2877; 03-10-2007 at 04:31 AM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!


  •  

    Posting Permissions

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