Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > PHP cal and events

PHP cal and events
Thread Tools
1c3
Forum Regular
Join Date: May 2003
Location: J�mtland - Sweden
Status: Offline
Reply With Quote
Sep 13, 2003, 02:49 PM
 
Hi there!

I have now managed to make a calendar, and made it possible to add events, but I have one small prolem:

I want to show who has added events on a particular day with color, each user has his own color. The way I have it now it looks like this:

function that switches the $col variable depending on the author of the event.

a while loop that renders the cal {
in that while loop, just before the table cell with the date currently being output i have made an SQL-query that grabs the days events. and after that query I run the function
}

is this a proper way to do this?
I thought that it would be a smart way to do it, but it doesn't seem to work

the code:

// Change Variable values to colors
function changeCol() {

switch($r) {
case "Admin": $col="\#FF0000"; break;
case "Snor": $col="\#FF0000"; break;
}
}


while(checkdate($month , $i - $_firstday , $today['year'])) {
if(( $i - 1) % 7 == 0) {
echo "</tr>\n<tr>\n";
}

$b = $i - $_firstday;

if($i == $today2) {

$r=mysql_fetch_array(mysql_query("SELECT * FROM cal WHERE b LIKE '$b'"));
changeCol();
echo "<td class=\"today\" onmouseover=\"this.style.backgroundColor='#ffffff' ;\" onmouseout=\"this.style.backgroundColor='#666666'; \"><a href=\"viewEvents1.php?day=$b&month=$today[month]\" target=\"calSmall\">$b</a><font color=\"$col\">$r[who]</font></td>";

}

and some more, but I don't think that is needed to show^^
I think you understand how I mean at least
Mighty3k @ #MacNN
     
wallinbl
Professional Poster
Join Date: Dec 2001
Location: somewhere
Status: Offline
Reply With Quote
Sep 13, 2003, 09:59 PM
 
You should keep the users in a table. Add a column to the table to represent the color to use when displaying events. Then, when you run the query to get the list of events for the day, join the users table and pick up the color from there.

There are two problems with your original approach:

First, you have hardcoded your users in a case statement. What if you add a user or change a user's color? You have to alter your code.

Second, you are looking up the color each iteration through the loop. With your hardcoded users & colors, the cost of this is low, but it's still there.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 03:15 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,