Php event calendar display help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

phpcoder123
Forum Newbie
Posts: 11
Joined: Wed Jun 24, 2009 3:30 pm

Php event calendar display help

Post by phpcoder123 »

Hi,
I have a requirement wherein I need to display records that have maximum number of occurance of a particular field first.
For eg, there are three days, where 1st day has two events of blue and brown color. Second has 3 events of blue, brown and red color and third has two events of blue and red color. Everything is dynamic and this is a event calendar I am talking about. I want that all the blues should be in one line,red in one and brown in one. Right now what happens is they do not come in a single straight line across all the three days. Please Help..

Thanks
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Php event calendar display help

Post by Eric! »

Just insert font tags for the colors. I don't know what your code structure is but this is the idea:

Code: Select all

if(I_NEED_BLUE)
{
    echo '<font size="3" color="blue">'.$event_text_output.'</font>';
}
if(I_NEED_RED)
{
    echo '<font size="3" color="red">'.$event_text_output.'</font>';
}
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Php event calendar display help

Post by califdon »

It's hard to understand what you want as output. Is it something like this?

Code: Select all

Day 1:  TypeA Event  TypeB Event
Day 2:               TypeB Event  TypeC Event
Day 3:  TypeA Event               TypeC Event
???

If it's something like that, you need to process your query in a particular order so that you can tell whether, on a particular day, there is or is not each possible event type, which will allow you to decide whether or not to output data for each possible display position.

I can't suggest specific code because I have no idea what kind of data you have, not to mention how you want it to appear.
phpcoder123
Forum Newbie
Posts: 11
Joined: Wed Jun 24, 2009 3:30 pm

Re: Php event calendar display help

Post by phpcoder123 »

I think you are right..It is something like
Day 1 Day 2 Day 3
Event 1 Event 1 Event 2
Event 2 Event 2 Event 3
Event 3

Now Event 1 is color red. Event 2 is blue and event 3 is brown.
What I want that I need to display all the events 1 in one line so that its appears to be a single red bar. And same for event 2 and 3.
Right now what I am doing is running a loop for day1 displaying all events in <td>, then for day2 and so on. So the events do not appear in
a single line, something like above where event 2 for day2 and day 3 ar not in a line. So it will be 2 rectangles of blue above and below rather than a single line. I want something similar to output.
Hope this makes sense!
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Php event calendar display help

Post by Eric! »

Your loop needs to run through the events, not the days. Build one line at a time and place the event in the proper column depending on which day it occurs.

For the coloring just set the html tags for each line or event.

If you want more specific advice you have to post your code.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Php event calendar display help

Post by califdon »

A word of advice: don't show us what you DON'T want, show us what you DO want, and do your thinking that way, too. It's usually more helpful to think in terms of the objective, not all the possible wrong solutions. That should lead you to the conclusion that ~Eric! just stated for you, and what I said earlier: you have to process your query in the order that you need to construct your HTML table. Since you want each row to be a particular type, you have to process all those records before moving on to the next type. While you're processing each type, you have to check each day to see if it has an event of that type. That will lead to an ORDER BY clause with type first, then day.
phpcoder123
Forum Newbie
Posts: 11
Joined: Wed Jun 24, 2009 3:30 pm

Re: Php event calendar display help

Post by phpcoder123 »

Code: Select all

$query = "select id,bid,user,title,starttime,endtime,approved from ".$EVENTS_TB." left join ".$CAT_TB." on ".$EVENTS_TB.".status=".$CAT_TB.".st_id where day='$i' and month='$month' and year='$year'" ;
           
            $query = $query." order by id,day,month,year,starttime,title ASC";
                $result = mysql_query($query);
                
            if (mysql_num_rows($result)!=0) {
            $countev = $countev + mysql_num_rows($result) ;
            echo "\n<table border=0 cellspacing=0 cellpadding=0 width=100%>" ;
                while ($row = mysql_fetch_object($result)){
                                
                $usernm=$row->user;             
                $qry="select bcolor from calendar_brand where br_id='".$row->bid."'";
                $res1=mysql_query($qry);
                $rs1=mysql_fetch_array($res1);
                
                if ($usernm=='admin')
                $ucolor='#e1cdb2';
                else
                $ucolor=$rs1["bcolor"];
                
            echo "<tr><td align=center valign=top " ;
                        echo ">" ; 
            echo "<table class=eventborder cellspacing=0 cellpadding=0 width='100%'><tr>";
            
            echo "<td align=left valign=top ";
            if ($gid!='0') echo "bgcolor='$ucolor'";
            echo " width='80%' class=eventborder>" ;
            if ($showuserentry==1) echo "<".$row->user."> " ;
            echo "<a class=smallcalev href=cal_event.php?op=view&id=".$row->id.">";
                  echo stripslashes($row->title)."</a>" ;
            echo "</td></tr>" ;
            echo "</table>" ;
                  }
            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;
              }
 
        }
Last edited by califdon on Thu Jun 25, 2009 1:53 pm, edited 1 time in total.
Reason: Added [php] tags. Note to poster: please learn how to do this when you post code here.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Php event calendar display help

Post by califdon »

I haven't much time today, but for starters, it looks to me like your original query should have another join so that you get the value of the color in the original result. There should be no need for more than one query. Then the color value should be the primary sort, after id, in your ORDER BY clause. Now as you fetch each row, you will be looking for whether there is a "red" event on Day 1, and if so, you output that bid, otherwise you show a blank cell, then whether there is a "brown" (or whatever color) on Day 2, then on Day 3. Only then will you fetch another row.

The general issue here is having a clear concept of what these entities are that you want to display, and what entities are stored in your database tables. That is, what does each row of your display represent? I really don't have a clear concept of that, so I'm unable to offer very much advice. But YOU have to have a crystal clear concept of this, and if you concentrate on seeing the problem in that light, you should be able to see how to do this.
phpcoder123
Forum Newbie
Posts: 11
Joined: Wed Jun 24, 2009 3:30 pm

Re: Php event calendar display help

Post by phpcoder123 »

You are right, I could have used another join instead of using 2 queries.
But that won't solve the problem. I have attached an image to get an idea of how it looks. I want that the two red events displayed should be in one single line.So that it looks like a red bar the way it now looks for blue and the brown one.
Attachments
img.jpg
img.jpg (24.92 KiB) Viewed 1391 times
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Php event calendar display help

Post by Eric! »

So you've fixed the sorting problem?

Instead of making an image, create the same thing in html with an editor. Then pick apart the html so you can echo the static bits and see where you need to echo your events. With some debugging you should be able to make your dynamic page output the same html as the example code from your editor.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Php event calendar display help

Post by califdon »

What's confusing me substantially is that you keep showing us what you DON'T want. That's bad thinking, in the first place, and almost guarantees that we won't understand what you DO want. Eric! has made a very good suggestion: create an HTML table and color the <td>'s the way you WANT them to be. Then you will be able to see where the dynamic parts must be, and what will determine the correct color. Then you will be able to see what order your query must be in. From there, it's just the details of the loop that creates each <td> within each <tr> and deciding whether to output the color or not. That won't be hard at all.
phpcoder123
Forum Newbie
Posts: 11
Joined: Wed Jun 24, 2009 3:30 pm

Re: Php event calendar display help

Post by phpcoder123 »

Hi Eric!,
Is it possible for you to write a sample code to explain me how to proceed with this?

Thanks
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Php event calendar display help

Post by Eric! »

Just get yourself a free HTML editor off the internet that does wysiwyg (what you see is what you get) so you can visually make your page look the way you want it to appear.

So then make an example week with all the features you want your dynamic php script to be able to do.

Then you can view the HTML source code of your newly created page with either your editor or view it with your browser (view->source) and you will be given all the html tags you need to make your calendar.

The hard work begins now. You need to make the events dynamic with php. You'll want to change the font tags dynamically for the colors and the text fields for your event names. All of the other html tags can be left static and you can use php to change the font colors and field text.

The code flows something like this

Code: Select all

<? // your php code to determine events and days and colors
 
// echo out the static html tags to the start of your first event
 
// process your event and color code and echo the tags (see my earlier post)
// after you've echoed out all your event data, echo out the closing static html tags.
Hopefully this gets you pointed in the right direction.
phpcoder123
Forum Newbie
Posts: 11
Joined: Wed Jun 24, 2009 3:30 pm

Re: Php event calendar display help

Post by phpcoder123 »

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%>" ;
            while ($row = mysql_fetch_object($result)){
            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>" ;
                              }
            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 have a look at the code, you shall see that I have already applied the html code like you suggested from the editor. What happens is that not all the events on all days appear in a bar. Something like in outlook. Can you suggest how can I alter the code I have pasted above to meet this requirements.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Php event calendar display help

Post by Eric! »

phpcoder123 wrote: What happens is that not all the events on all days appear in a bar. Something like in outlook.
The hard work will be getting the formatting right. I don't understand your problem from your short description. Can you post the html output from your script and provide more details?
Post Reply