Styles2304 Posted August 24, 2007 Share Posted August 24, 2007 Ok, here is the code that controls how the calendar is created: <?php include "conn.inc.php"; $day = $_GET["day"]; $month = $_GET["month"]; $year = $_GET["year"]; if ($day == "") $day = date("j"); if ($month == "") $month = date("n"); if ($year == "") $year = date("Y"); $currentTimeStamp = strtotime("$year-$month-$day"); $monthName = date("F", $currentTimeStamp); $numDays = date("t", $currentTimeStamp); $counter = 0; ?> <LINK REL=StyleSheet HREF="calendar.css" TYPE="text/css"> <table width='168' height="121" border='0' cellspacing='2' cellpadding='0'> <tr> <td colspan="7" class="title"> <font class="title"> <center> <?php echo date("F");?> </center> </font> </td> </tr> <tr class="daylabels"> <td class='blank' width='24'>Sn</td> <td class='blank' width='24'>Mn</td> <td class='blank' width='24'>Tu</td> <td class='blank' width='24'>Wd</td> <td class='blank' width='24'>Th</td> <td class='blank' width='24'>Fr</td> <td class='blank' width='24'>St</td> </tr> <tr class="date"> <?php for ($i = 1; $i < $numDays + 1; $i++, $counter++) { $timeStamp = strtotime("$year-$month-$i"); if ($i == 1) { //Figures out when the first day of the month is $firstDay = date("w",$timeStamp); for($j = 0; $j < $firstDay; $j ++, $counter++) echo "<td width='24' height='16' class='blank'> </td>"; } if($counter % 7 == 0) { echo "</tr><tr class='date'>"; } if (date("w", $timeStamp) == 0 || date("w", $timeStamp) == 6) { echo "<td width='24' height='16' class='weekend'>$i</td>"; } else { if ($i == date("d") && $month == date("m") && $year == date("Y")){ echo "<td width='24' height='16' class='today'>$i</td>"; } else { echo "<td width='24' height='16' class='normal'>$i</td>"; } } } ?> </table> I'd like to do a typical event calendar where if there is an event (which is stored in a database) it will highlight whatever day the event takes place on. I'm sorry if this is kind of a broad question but can someone either show me or point me towards a tutorial that can tell me how to accomplish this? I know it will require a foreach loop (at least I think so) and it will check, in this case, the day of the event against $i and if they equal it will set that particular table column's class to event I'm just not sure how to actually implement that with the code I currently have. Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/ Share on other sites More sharing options...
chocopi Posted August 24, 2007 Share Posted August 24, 2007 Have you tried this tutorial http://www.phpfreaks.com/tutorials/83/0.php ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333228 Share on other sites More sharing options...
Styles2304 Posted August 24, 2007 Author Share Posted August 24, 2007 Thanks for the quick response but I have the actual calendar part worked out pretty well. I just need to figure out how to have it look through a list of events and compare it to days and then change the class. Does that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333243 Share on other sites More sharing options...
Styles2304 Posted August 24, 2007 Author Share Posted August 24, 2007 I searched for quite awhile for tutorials but I'm completely at a loss . . . can anyone give me some guidance here? Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333278 Share on other sites More sharing options...
Styles2304 Posted August 24, 2007 Author Share Posted August 24, 2007 I guess I can narrow my question . . . how do I make it so that if a check of the database returns true, it will change the class of the table? Something like if event == y where date == whatever . . . it will change the class when $i == date. Does that make sense? Well, actually, I could probably even do that myself but I need to do a check of "date" in this case assuming that it holds many dates . . . I don't even know it's so damn aggravating when you don't even know enough to be able to ask the right damn question. Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333395 Share on other sites More sharing options...
Styles2304 Posted August 25, 2007 Author Share Posted August 25, 2007 I really don't know what else to do other than bump this up. Just to re-iterate . . . I'm wanting to pull the dates of events out of the database (I know how to do that) and then compare them to $i . . . if any of the dates == $i then I want to do: <td width='24' height='16' class='event'><a href='##?IndexNo=' . $IndexNo . '">$i</a></td> for that particular date and then continue down the list. I know this requires a foreach or a for but I'm not clear on the mechanics yet. I'm pretty desperate here as I've been working on this control panel for my Church for awhile now only to realize that I'm kind of over my head. I've gotten everything else but this figured out (thanks to you guys). Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333609 Share on other sites More sharing options...
XaeroDegreaz Posted August 25, 2007 Share Posted August 25, 2007 Ok before I start coding, let me get this straight. You want to pull dates out of a database, and if the date matches your variable, then you want it to do what? Change the css class for that table? Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333612 Share on other sites More sharing options...
XaeroDegreaz Posted August 25, 2007 Share Posted August 25, 2007 <?php $query = mysql_query("Your query here"); $i = "What you want to match"; while($rs = mysql_fetch_assoc($query) { //Insert your code here for what you want to happen, for each result in the database if($rs["the name of the field you want to match"] == $i) { echo("<td width='24' height='16' class='event'><a href='##?IndexNo=$IndexNo'>$i</a></td>"); }else { //Here you echo what you want it to look like if it does NOT match what you want } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333614 Share on other sites More sharing options...
micmania1 Posted August 25, 2007 Share Posted August 25, 2007 <?php $query = "SELECT * FROM dates GROUP BY date"; // This will return each date once only $result = mysql_query($query); $num = mysql_num_rows($result); if ($num > 0) { // if there is at least 1 record while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row['date'] == $yourdate) { $query1 = "SELECT * FROM dates WHERE date='{$row['date']}'"; // Select each record for each each single date $result1 mysql_query($query1); $num1 = mysql_num_rows($result1); if ($num1 > 0) { // There is at least 1 record on that day while ($row1 = mysql_fetch_array($result1, MYSQL_ASSOC)) { echo '<tr><td>'.$row['event_name'].'</td><td>'.$row['date'].'</td></tr>'; // echo each record } } } // else the event is not on your specified day } } else { // could not find any records echo 'There are no records.'; } ?> Obviously i've made up the table and column names but if you rewrite what i've just done and implementit into your script it should get records for each day and if there is more than 1 record on that day, it will display them all. I think that is what your after anyway. The if statement "if ($row['date'] == $yourdate) {" was added after submitting my form and readin what Xaero had wrote. I'm not fully sure which you are trying to do but hopefully you can gain something from this post. Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333616 Share on other sites More sharing options...
XaeroDegreaz Posted August 25, 2007 Share Posted August 25, 2007 Hehe yeah I kept editing my post over and over adding stuff to it hehe Trying to figure out exactly what he wants to do, but I think we pretty much covered the bases. Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333617 Share on other sites More sharing options...
Styles2304 Posted August 25, 2007 Author Share Posted August 25, 2007 Ok well I appreciate your help guys . . . I'm gonna have to wade through this stuff and see if I have enough know how to apply it! Again, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333625 Share on other sites More sharing options...
Styles2304 Posted August 25, 2007 Author Share Posted August 25, 2007 I gotta tell you . . . I don't know where or how I can incorporate that with the script that I posted originially . . . can someone give me a little further guidance? Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333637 Share on other sites More sharing options...
Styles2304 Posted August 25, 2007 Author Share Posted August 25, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333853 Share on other sites More sharing options...
AndyB Posted August 25, 2007 Share Posted August 25, 2007 If you're terminally stuck, you could use my script - http://digitalmidget.com/php_noob/calendar.php Needless to say, you'll learn more if you persevere with your own but that script might save your sanity Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333854 Share on other sites More sharing options...
Styles2304 Posted August 25, 2007 Author Share Posted August 25, 2007 I'm just not sure how to incorporate all the loops . . . it's tricky stuff. Is my base code for the calendar itself wrong or is this just a harder than usual code to figure out? I'm gonna download yours and see if I can't figure out what I'm doing wrong. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333857 Share on other sites More sharing options...
Styles2304 Posted August 25, 2007 Author Share Posted August 25, 2007 I think I understand your code enough to make it work except for one part. Andy, can you explain this a little a bit? : { $found = $myrow['ev_dat']; $pieces = explode("-", $found); $dd = intval($pieces[2]); $ev_dat[$dd] = $myrow['id']; } Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333868 Share on other sites More sharing options...
AndyB Posted August 25, 2007 Share Posted August 25, 2007 $found is something from the database row (the event date in yyyy-mm-dd format, as I recall) explode() breaks that up into pieces at the - delimiter into an array (three elements, numbered 0,1, and 2) $pieces[2] is the third element of the date, i.e. the day number $ev_dat[] is then an array element linked back to the database record for a day's information Does that help? Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333877 Share on other sites More sharing options...
Styles2304 Posted August 25, 2007 Author Share Posted August 25, 2007 Ok . . . yeah that makes sense I didn't think to link the data format to explode so I was a little confused. Maybe i should just back off of this one . . . but I still can't understand how it does the check for each day without using foreach or something I appreciate all your help but I guess I'll just try to find an alternative like doing it by hand in html >_< Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333882 Share on other sites More sharing options...
Styles2304 Posted August 25, 2007 Author Share Posted August 25, 2007 Ok well, I looked through your stuff some more and while I didn't understand all of it . . . I did this: $query = "SELECT EventDate FROM CalendarEvents WHERE (MONTH(EventDate) = " . $month . ");"; $result = mysql_query($query, $link) or die(mysql_error()); $EventDate = array(); while ($row = mysql_fetch_array($result)) { $found = $row['EventDate']; $pieces = explode("-", $found); $ed = ($pieces[2]); $EventDate[$ed] = "1"; } coupled with : if ($EventDate[$i]) { echo "<td width='24' height='16' class='event'><a href='showevent.php?day=$i' class='calendar'>$i</a></td>"; That pretty much covered it. I had additional code in there in case it was an event AND today but it's just slightly modified. Thank you guys for making me think. Quote Link to comment https://forums.phpfreaks.com/topic/66538-solved-help-with-event-calendar-or-good-tutorial-to-follow/#findComment-333941 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.