Page 2 of 2

Re: Php event calendar display help

Posted: Tue Jun 30, 2009 1:39 pm
by phpcoder123
I want the pink events in the single bar just like the blue ones.
Thanks for all your help and sorry for the confusion:(

Re: Php event calendar display help

Posted: Tue Jun 30, 2009 1:47 pm
by Eric!
I would have preferred the actual html code output from your script. Is this a screen shot of your browser?

Anyway I understand what you are trying to do now. You will also need to add an extra conditional to your output loop. When you find an event (a pink one) you need to search the rest of the week for similar colored events and only output events that match the color of the line you are echoing. Then switch to the blue events, search the whole week and only output blue events on the next line, and so on. If you find multiple blue events for example on the same day, you'll need to just make new lines to accomidate each line of blue events.

Re: Php event calendar display help

Posted: Tue Jun 30, 2009 2:16 pm
by phpcoder123
You are right, that was the screenshot of my browser.

Also, what needs to happen is that somewhere the position of the event has to be locked once the first time it appears. Here what happens is the pink event gets displayed first and the blue gets displayed later on, but on the day when there are both the event, the blue appears than the pink appears. Then on other day there is only the blue event and so it gets displayed where blue gets displayed on 25th. If I am able to lock the position of pink when it appears for the first time, here it would be position 1 on day 24th, then on day 25th it should appear on position 1 and the blue on position 2. This position when the blue appears for the first time should be locked and so all the following blue events should appear on position 2. Do you have any idea how to achieve this.Hope this does make sense..

Re: Php event calendar display help

Posted: Tue Jun 30, 2009 2:34 pm
by Eric!
I thought I explained how to do that, but I'll try again. Maybe I'm not getting what you want exactly either....

Group your weeks events by color. Search for all the pinks. Search for all the blues, etc.
Choose one color group to output on the first line, say pink. Print all the days with a pink event. Then if you have any days with multiple pink events, print those too.

Now you have just created all the lines in the calendar for the pinks. Now loop through all the blue events and print their events. Print any multiple blue event days too. Now repeat for the other colors.

This will make something like

Pink Event Pink Event ----
----- Pink Event ----
Blue Event Blue Event ----

Re: Php event calendar display help

Posted: Tue Jun 30, 2009 2:35 pm
by Eric!
I thought I explained how to do that, but I'll try again. Maybe I'm not getting what you want exactly either....

Group your weeks events by color. Search for all the pinks. Search for all the blues, etc.
Choose one color group to output on the first line, say pink. Print all the days with a pink event. Then if you have any days with multiple pink events, print those too.

Now you have just created all the lines in the calendar for the pinks. Now loop through all the blue events and print their events. Print any multiple blue event days too. Now repeat for the other colors.

This will make something like

Code: Select all

Pink Event          Pink Event         ----
-----               Pink Event         ----
Blue Event          Blue Event         ----

Re: Php event calendar display help

Posted: Wed Jul 01, 2009 3:48 pm
by phpcoder123
I got what you are trying to say. But can you give me a hint as to how can I put it into implementation looking at the code that I uploaded on the forum?

Re: Php event calendar display help

Posted: Wed Jul 01, 2009 5:00 pm
by Eric!
Ok, I have no way of testing this snipet of code. It might have serious problems and I also don't have your full script or the data from your database...so nothing may work. I do think you're going to run into a problem with the html tags not showing up right.

Does this snipet get run to display one day only or a full week? I assumed you are doing a full week at a time. How this is supposed to work is an array $colors is built from your data query from the database. Only unique colors are inserted in the list in the order at which they are found in the database results.

Then it loops through the list of $colors and checks your events. If an event matches the current color, it prints it out. So all the line for all the blues gets printed. I'm confused about the format of your html. It seems you need to print blanks on days with no events.

Anyway after searching the data for all the matching color events, it moves on to the next color in the list and scans all the data again. And so on.

I seriously doubt this code will work exactly how you want it. But you will get the idea and hopefully build from there.

Code: Select all

             $query = "select id,bid,user,title,starttime,endtime,bcolor from ".$EVENTS_TB." left join calendar_status on ".$EVENTS_TB.".status=calendar_status.st_id left join calendar_brand on calendar_events.bid=calendar_brand.br_id where day='$i' and month='$month' and year='$year' and approved='1' " ;          
 
            $query = $query." order by id,bcolor,day,month,year,title ASC";
                             $result = mysql_query($query);
            $devtcnt = mysql_num_rows($result) ;
          echo "<table border=0 cellspacing=0 cellpadding=0 width=100%>" ;
            //Make color list
            $colors=array(); //start with empty color list
            while ($row = mysql_fetch_object($result))
            {
               if(!in_array($row->bcolor,$colors))
               {
                  $colors[]=$row->bcolor; //add this color to the list of colors we need to show
               }
            }
            echo "<pre>".var_dump($colors)."</pre>"; //debugging list of colors remove if list looks correct
            mysql_data_seek($result,0); //reset to start of list so mysql_fetch_object starts at the top of the list again
            foreach($colors as $color) //loop through the colors
            {
              while ($row = mysql_fetch_object($result))
              {
                if($row->bcolor==$color) //matches color in list print it
                {
                  echo "<tr><td align=center valign=top>\n" ;
                  echo "<table class=eventborder border=1 cellspacing=0 cellpadding=0 width='100%'><tr>";                          
                                            $bcolor=$row->bcolor;
                  echo "<td align=left valign=top width='80%' class=eventborder bgcolor=$bcolor>" ;
                  echo "<a class=smallcalev href=cal_event.php?id=".$row->id.">";
                                            echo stripslashes($row->title)."</a>" ;
                  echo "</td></tr>" ;
                  echo "</table>" ;
                } // Event gets skipped if it doesn't match the current color to display
                   // seems like you need some code in here for printing empty spaces for days with no events or
                   // only one event next to a day with 2+ events...need to fill in the blanks?      
              }
              // Ok we ran through the data only pulling out items of the same color
              // now we will pull out the next color and loop through the data again
              mysql_data_seek($result,0); //reset to start of list             
            }
            // Done with all colors
            // I don't understand how this loop works exactly
            // there is no provision for printing blank spaces on days with no events
            // Since I don't have all the code or know what your data looks like
            // I assume you have this sorted out
            echo "</table>\n" ;
            }
            echo "</td>";
            $a++;
           
        if (blankdays(intval($weekstartday),date("w",mktime(0,0,0,$month,$i,$year))) == 6)
        {
              echo "</tr>\n\n<tr>";
              $a = 0;
        }
    }
If you are only running this snippet for a single day's events, then you might want to build a sql query to get all the colors of the events used for the week and then reserve space in each day for that color whether it is blank or and event...

Re: Php event calendar display help

Posted: Thu Jul 02, 2009 9:22 am
by phpcoder123
Hi Eric!
Thanks so much for puttin so much effort on this.
I tried it but it won't work because the loop runs through one day displays all the events and then moves on to other day.
So like you assumed there are problems with html display. I shall keep on working and see what I can do.
Actually, I downloaded the event calendar code from net and customised it to my requirements as I needed it done really fast. But this way it took more time:(!

Re: Php event calendar display help

Posted: Thu Jul 02, 2009 10:02 am
by Eric!
I was afraid of that. It might be easier for you to do a full week at a time and insert blanks on days with no events matching the current color choice. My code will work either way, except you will only want to show events for the day you are echoing.

As you get closer post the full code again if you need more help.