rockindano30 Posted May 16, 2008 Share Posted May 16, 2008 Hello all, i'm working on a calendar actually a event calendar. a calendar that when you hover over a date that has an event displays a hovering box with event info. now i have it working to where it displays the calendar and grabs the info from db and when hover over a date box appears but, my problem is all days are links and box has all the events in the db for every day. this is my code for any suggestions or help <h3 style="font-family:palatino linotype; color:#9e865f">Calendar</h3><br /> <?php // Get values from query string $day = $_GET["day"]; $month = $_GET["month"]; $year = $_GET["year"]; $sel = $_GET["sel"]; $what = $_GET["what"]; if($day == "") $day = date("j"); if($month == "") $month = date("m"); if($year == "") $year = date("Y"); $currentTimeStamp = strtotime("$year-$month-$day"); $monthName = date("F", $currentTimeStamp); $numDays = date("t", $currentTimeStamp); $counter = 0; $numEventsThisMonth = 0; $hasEvent = false; $todaysEvents = ""; ?> <table width="100%" border='0' cellspacing='0' cellpadding='0'> <tr align="center"> <td width="87" colspan='1' align="center"><input type='button' value='<<' onClick='goLastMonth(<?php echo $month . ", " . $year; ?>)'> </td> <td colspan='5' align="center"><span class='title'><?php echo $monthName . " " . $year; ?></span><br> </td> <td width="87" colspan='1' align='center'><input type='button' value='>>' onClick='goNextMonth(<?php echo $month . ", " . $year; ?>)'> </td> </tr> <tr> <td class='style2'>S</td> <td width='80' class='style2'>M</td> <td width='80' class='style2'>T</td> <td width='80' class='style2'>W</td> <td width='80' class='style2'>T</td> <td width='80' class='style2'>F</td> <td class='style2'>S</td> </tr> <?php $numDays = date("t", $currentTimeStamp); for($i = 1; $i < $numDays+1; $i++, $counter++) { $timeStamp = strtotime("$year-$month-$i"); if($i == 1) { // Workout when the first day of the month is $firstDay = date("w", $timeStamp); for($j = 0; $j < $firstDay; $j++, $counter++) echo "<td align='center'> </td>"; } //end if if(!($db = @ mysql_connect('localhost', 'user', 'pass'))) { echo 'Error: Could not connect to our database sorry for any inconvience.<br /> Please try at a later time.'; exit; } //select which database you want to edit mysql_select_db("db_name_here"); // $event_id = $_GET["event_id"]; $eventdate=$_GET["dateevent"]; if(!isset($eventdate)) { $query = "SELECT group_concat(title separator ' - ') as title FROM calendar"; $result = mysql_query($query); while($r=mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; $event_id=$r["event_id"]; $date=$r["dateevent"]; $title=$r["title"]; $eventdate = strtotime($date); ?> <?php //prints out all days here................... if($counter % 7 == 0) print "</tr><tr align='center'>"; if(date("w", $timeStamp) == 0 || date("w", $timeStamp) == 6) print "<td width='50' class='weekend' align='left'>$i</td>"; else if($i == date("d") && $month == date("m") && $year == date("Y")) print "<td width='50' class='today' align='left'><div id=\"links\"><a href\"\">$i<span>$title</span></a></div></td>"; else print "<td width='50' class='normal' align='left'><div id=\"links\"><a href\"\">$i<span>$title</span></a></div></td>"; } }//end if/////////////////////////// }//end of for loop ?> any help??? Quote Link to comment Share on other sites More sharing options...
rockindano30 Posted May 16, 2008 Author Share Posted May 16, 2008 i know my code might need some adjustments. but got the calendar working i just need that extra event info to be display. Quote Link to comment Share on other sites More sharing options...
rockindano30 Posted May 16, 2008 Author Share Posted May 16, 2008 the concat title needs to be removed. however , i now that i'm missing a for loop inside my while loop. just a little stuck in thinking how to get all events from table and assigning them to the correct days. ?????? Quote Link to comment Share on other sites More sharing options...
rockindano30 Posted May 16, 2008 Author Share Posted May 16, 2008 can anybody point me to the direction of a tutorial similar to this Quote Link to comment Share on other sites More sharing options...
jacksonmj Posted May 16, 2008 Share Posted May 16, 2008 Within your for loop that is iterating through all the days of the month, for each day you are fetching all the events from the database and outputting them. Try replacing your for loop that is currently iterating through the days of the month with something like this (NOTE: this code has not been tested at all and might fail miserably or require major adjustments!): if(!($db = @mysql_connect('localhost', 'user', 'pass'))) { echo 'Error: Could not connect to our database sorry for any inconvience.<br /> Please try at a later time.'; exit; } mysql_select_db("db_name_here"); for($i = 1; $i < $numDays+1; $i++, $counter++) //iterate through days { $timeStamp = strtotime("$year-$month-$i"); if($i == 1) { // Workout when the first day of the month is $firstDay = date("w", $timeStamp); for($j = 0; $j < $firstDay; $j++, $counter++) echo "<td align='center'> </td>"; } //end if if($counter % 7 == 0) print "</tr><tr align='center'>"; $weekend = ""; if(date("w", $timeStamp) == 0 || date("w", $timeStamp) == 6) $weekend = " weekend"; //find events for current day $query = "SELECT event_id, title FROM calendar WHERE dateevent = '$year-$month-$i'"; $result = mysql_query($query); if (mysql_num_rows($result)) //checks whether any events found for this day { if($i == date("d") && $month == date("m") && $year == date("Y")) print "<td width='50' class='today$weekend' align='left'><div id=\"links\"><a href\"\">$i<span>"; else print "<td width='50' class='normal$weekend' align='left'><div id=\"links\"><a href\"\">$i<span>"; $date = "$year-$month-$i"; //this code is outside the following while loop to prevent a ' - ' in front of the first event title: $r=mysql_fetch_array($result); $event_id=$r["event_id"]; $title=$r["title"]; print $title; while($r=mysql_fetch_array($result)) { print " - "; $event_id=$r["event_id"]; $title=$r["title"]; print $title; } print "</span></a></div></td>"; } else //no events for this day { if($i == date("d") && $month == date("m") && $year == date("Y")) print "<td width='50' class='today$weekend' align='left'>$i</td>"; else print "<td width='50' class='normal$weekend' align='left'>$i</td>"; } } Quote Link to comment Share on other sites More sharing options...
rockindano30 Posted May 16, 2008 Author Share Posted May 16, 2008 dude Jack, thank you very much. it work!!!! . Quote Link to comment 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.