xiaoxin22 Posted June 13, 2010 Share Posted June 13, 2010 need some advice here.. did a event calender but i couldn't get it to extract the events from datatbase and show it.. something like picture below.. http://www.k5n.us/articles/img-0003B.png and this is what i've done.. please give me some advice. thank you. <?php function showCalendar(){ // Get key day informations. // We need the first and last day of the month and the actual day $today = getdate(); $firstDay = getdate(mktime(0,0,0,$today['mon'],1,$today['year'])); $lastDay = getdate(mktime(0,0,0,$today['mon']+1,0,$today['year'])); echo '<h2>' . $today['year'] . '</h2>'; // Create a table with the necessary header informations echo '<table id="form_part">'; echo ' <tr class="table_header"><td class="page_link">Last Month</td><td colspan="5">' . $today['month'] . '</td><td class="page_link">Next Month</td></tr>'; echo '<tr class="table_header2">'; echo ' <td><strong>Monday</strong></td><td><strong>Tuesday</strong></td><td><strong>Wednesday</strong></td><td><strong>Thursday</strong></td>'; echo ' <td><strong>Friday</strong></td><td><strong>Saturday</strong></td><td><strong>Sunday</strong></td></tr>'; // Display the first calendar row with correct positioning echo '<tr>'; for($i=1;$i<$firstDay['wday'];$i++){ echo '<td> </td>'; } $actday = 0; for($i=$firstDay['wday'];$i<=7;$i++){ $actday++; if ($actday == $today['mday']) { $class = ' class="actday"'; } else { $class = ''; } echo "<td$class>$actday</td>"; } echo '</tr>'; //Get how many complete weeks are in the actual month $fullWeeks = floor(($lastDay['mday']-$actday)/7); for ($i=0;$i<$fullWeeks;$i++){ echo '<tr>'; for ($j=0;$j<7;$j++){ $actday++; if ($actday == $today['mday']) { $class = ' class="actday"'; } else { $class = ''; } echo "<td$class>$actday</td>"; } echo '</tr>'; } //Now display the rest of the month if ($actday < $lastDay['mday']){ echo '<tr>'; for ($i=0; $i<7;$i++){ $actday++; if ($actday == $today['mday']) { $class = ' class="actday"'; } else { $class = ''; } if ($actday <= $lastDay['mday']){ echo "<td$class>$actday</td>"; } else { echo '<td> </td>'; } } echo '</tr>'; } echo '</table>'; } showCalendar(); ?> Link to comment https://forums.phpfreaks.com/topic/204625-question-about-event-calender-advice-please/ Share on other sites More sharing options...
xiaoxin22 Posted June 17, 2010 Author Share Posted June 17, 2010 Thanks for reading.. i have solved this problem with my own way but there is another problem.. haha... below is what i did.. <?php function load_events($actday){ $today = getdate(); $query = sprintf("SELECT * FROM c_details WHERE d_day = %s ORDER BY d_dn, d_hr ASC", mysql_real_escape_string($actday)); $result = mysql_query($query); $print = mysql_fetch_assoc($result); if ($actday == $today['mday']) { echo "<td class=actday>$actday"; } else { echo "<td>$actday"; } if ($print == ""){ echo "</td>"; } else { do { echo '<p>' . $print['d_hr'] . "." . $print['d_min'] . $print['d_dn'] . " " . $print['d_name'] . '</p>'; } while ($print = mysql_fetch_assoc($result)); echo "</td>"; } } function showCalendar(){ // Get key day informations. // We need the first and last day of the month and the actual day $today = getdate(); $month = $today['mon']; $firstDay = getdate(mktime(0,0,0,$month,1,$today['year'])); $lastDay = getdate(mktime(0,0,0,$month+1,0,$today['year'])); echo '<h2>' . $today['year'] . '</h2>'; // Create a table with the necessary header informations echo '<table id=form_part>'; echo ' <tr><td colspan="7" class=table_header>' . $today['month'] . '</td></tr>'; echo '<tr class=table_header2>'; echo ' <td><strong>Monday</strong></td><td><strong>Tuesday</strong></td><td><strong>Wednesday</strong></td><td><strong>Thursday</strong></td>'; echo ' <td><strong>Friday</strong></td><td><strong>Saturday</strong></td><td><strong>Sunday</strong></td></tr>'; // Display the first calendar row with correct positioning echo '<tr>'; for($i=1;$i<$firstDay['wday'];$i++){ echo '<td> </td>'; } $actday = 0; for($i=$firstDay['wday'];$i<=7;$i++){ $actday++; load_events($actday); } echo '</tr>'; //Get how many complete weeks are in the actual month $fullWeeks = floor(($lastDay['mday']-$actday)/7); for ($i=0;$i<$fullWeeks;$i++){ echo '<tr>'; for ($j=0;$j<7;$j++){ $actday++; load_events($actday); } echo '</tr>'; } //Now display the rest of the month if ($actday < $lastDay['mday']){ echo '<tr>'; for ($i=0; $i<7;$i++){ $actday++; if ($actday <= $lastDay['mday']){ load_events($actday); } else { echo '<td> </td>'; } } echo '</tr>'; } echo '</table>'; } showCalendar(); Link to comment https://forums.phpfreaks.com/topic/204625-question-about-event-calender-advice-please/#findComment-1073267 Share on other sites More sharing options...
xiaoxin22 Posted June 17, 2010 Author Share Posted June 17, 2010 how do i have order by 3 different requirements for sql query? and for the august of 2010, there seems to have some problem, can someone advice on that? Link to comment https://forums.phpfreaks.com/topic/204625-question-about-event-calender-advice-please/#findComment-1073271 Share on other sites More sharing options...
xiaoxin22 Posted June 17, 2010 Author Share Posted June 17, 2010 no help?? Link to comment https://forums.phpfreaks.com/topic/204625-question-about-event-calender-advice-please/#findComment-1073577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.