runnerjp Posted April 17, 2009 Share Posted April 17, 2009 sql = "SELECT * FROM events WHERE date='$d-$m-$y'"; echo $sql; $postsresult = mysql_query($sql); $row = mysql_fetch_array($postsresult); from the code above how could i find out if row['event'] from each day of the month had a result... so... Su M T W Th F Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 if the above is my calander and the 16th had an event i would want to show it by producing 16th with a link as it shows. im just stuggling how to see if there is a result for each day itself here is all my code for the calander <script src="http://www.runningprofiles.com/jquery.js" type="text/javascript"></script> <link href="http://www.runningprofiles.com/members/calendar/facebox/facebox.css" media="screen" rel="stylesheet" type="text/css"/> <script src="http://www.runningprofiles.com/members/calendar/facebox/facebox.js" type="text/javascript"></script> <script> jQuery(document).ready(function($) { $('a[rel*=facebox]').facebox() }) </script> <?php include '../../settings.php'; mk_drawCalendar($_GET['m'],$_GET['y']); $m = (!$m) ? date("m",mktime()) : "$m"; $y = (!$y) ? date("Y",mktime()) : "$y"; //********************************************************* // DRAW CALENDAR //********************************************************* /* Draws out a calendar (in html) of the month/year passed to it date passed in format mm-dd-yyyy */ function mk_drawCalendar($m,$y) { if ((!$m) || (!$y)) { $m = date("m",mktime()); $y = date("Y",mktime()); } /*== get what weekday the first is on ==*/ $tmpd = getdate(mktime(0,0,0,$m,1,$y)); $month = $tmpd["month"]; $firstwday= $tmpd["wday"]; $lastday = mk_getLastDayofMonth($m,$y); ?> <div align="center"> <table cellpadding="2" cellspacing="0" border="1"> <tr><td colspan="7" bgcolor="#00CCCC"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tr><th width="20"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>"><<</a></th> <th bgcolor="#00CCCC"><font size=2><?="$month $y"?></font></th> <th width="20"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?=(($m+1)>12) ? 1 : $m+1 ?>&y=<?=(($m+1)>12) ? $y+1 : $y ?>">>></a></th> </tr></table> </td></tr> <tr><th width=22 class="tcell">Su</th><th width=22 class="tcell">M</th> <th width=22 class="tcell">T </th><th width=22 class="tcell">W</th> <th width=22 class="tcell">Th</th><th width=22 class="tcell">F</th> <th width=22 class="tcell">Sa</th></tr> <?php $d = 1; $wday = $firstwday; $firstweek = true; /*== loop through all the days of the month ==*/ while ( $d <= $lastday) { /*== set up blank days for first week ==*/ if ($firstweek) { echo "<tr>"; for ($i=1; $i<=$firstwday; $i++) { echo "<td><font size=2> </font></td>"; } $firstweek = false; } /*== Sunday start week with <tr> ==*/ if ($wday==0) { echo "<tr>"; } /*== check for event ==*/ $sql = "SELECT * FROM events WHERE date='$d-$m-$y'"; echo $sql; $postsresult = mysql_query($sql); $row = mysql_fetch_array($postsresult); $num = mysql_num_rows($postsresult); if($row['event'] == 1) { echo "<td class='tcell'>"; echo "<a href=\"http://www.runningprofiles.com/test2.php?month=$d-$m-$y\" rel=\"facebox\" onClick=\"document.f.eventdate.value='$m-$d-$y';\">$d</a>"; echo "</td>\n"; } else {echo "<td class='tcell'>"; echo "<a href=\"1\" rel=\"facebox\" onClick=\"document.f.eventdate.value='$m-$d-$y';\">$d</a>"; echo "</td>\n";} /*== Saturday end week with </tr> ==*/ if ($wday==6) { echo "</tr>\n"; } $wday++; $wday = $wday % 7; $d++; } ?> </tr> </table> Please select the date your event is held on. <br /> <?php /*== end drawCalendar function ==*/ } /*== get the last day of the month ==*/ function mk_getLastDayofMonth($mon,$year) { for ($tday=28; $tday <= 31; $tday++) { $tdate = getdate(mktime(0,0,0,$mon,$tday,$year)); if ($tdate["mon"] != $mon) { break; } } $tday--; return $tday; } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/154485-solved-finding-results-from-a-row/ Share on other sites More sharing options...
sloth456 Posted April 17, 2009 Share Posted April 17, 2009 Can you tell us what the output is or provide a link we can view for ourselves? Quote Link to comment https://forums.phpfreaks.com/topic/154485-solved-finding-results-from-a-row/#findComment-812294 Share on other sites More sharing options...
runnerjp Posted April 17, 2009 Author Share Posted April 17, 2009 here is a link http://www.runningprofiles.com/members/calendar/test.php# so here is my db CREATE TABLE IF NOT EXISTS `events` ( `e_id` int(99) NOT NULL auto_increment, `e_event` varchar(50) NOT NULL default '', `e_start` datetime default NULL, `e_end` datetime default NULL, PRIMARY KEY (`e_id`), KEY `e_start` (`e_start`,`e_end`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; so what i want to know is... how can i see if the date on the calander has a event... if so show a link if not show text. the bold green part is what i cant figure outlol Quote Link to comment https://forums.phpfreaks.com/topic/154485-solved-finding-results-from-a-row/#findComment-812651 Share on other sites More sharing options...
keeB Posted April 17, 2009 Share Posted April 17, 2009 Update your mk_drawCalendar function. While drawing each day, check to see if there are events in the DB, if so, do whatever you'd like. If not draw as normal. Quote Link to comment https://forums.phpfreaks.com/topic/154485-solved-finding-results-from-a-row/#findComment-812655 Share on other sites More sharing options...
Maq Posted April 17, 2009 Share Posted April 17, 2009 If there's nothing scheduled for that date than it's going to have the default value... `e_event` varchar(50) NOT NULL default '', which is an empty string. So just check to see if the string isn't empty. if($row['event'] != '') { //add the link } else { //add the day but not the with the link } Quote Link to comment https://forums.phpfreaks.com/topic/154485-solved-finding-results-from-a-row/#findComment-812658 Share on other sites More sharing options...
soak Posted April 17, 2009 Share Posted April 17, 2009 I would select all the events for that month and put them into an array keyed by the date. So something like SELECT `e_event` FROM `events` WHERE `e_start` > FIRST_DAY_OF_MONTH AND `e_start` < LAST_DAY_OF_MONTH then loop that lot and create an events array like $events['2009-01-03'] = true; $events['2009-01-19'] = true; You can do this before you start rendering your calendar. Then when you're looping days and rendering your calendar you can call isset($events[$y.'-'.$m.'-'.$d]) to determine if there is an event on that particular day. This way you will only need to make 1 sql query to your database. If you wish you could even set the link title="TITLE" field to the name of the event. Quote Link to comment https://forums.phpfreaks.com/topic/154485-solved-finding-results-from-a-row/#findComment-812668 Share on other sites More sharing options...
runnerjp Posted April 17, 2009 Author Share Posted April 17, 2009 humm it not working ok in db i have this event start event finish 6 testing event 2009-04-11 10:00:00 2009-04-11 11:00:00 $sql = "SELECT * FROM events WHERE e_start='$d-$m-$y'"; echo $sql; $postsresult = mysql_query($sql); $row = mysql_fetch_array($postsresult); if($row['event'] != '') { echo "<td class='tcell'>"; echo "<a href=\"http://www.runningprofiles.com/test2.php?month=$d-$m-$y\" rel=\"facebox\" onClick=\"document.f.eventdate.value='$m-$d-$y';\">$d</a>"; echo "</td>\n"; } else { echo "<td class='tcell'>"; echo "$d"; echo "</td>\n"; } what am i doing wrong and soak thats just gone right over my head lol Quote Link to comment https://forums.phpfreaks.com/topic/154485-solved-finding-results-from-a-row/#findComment-812685 Share on other sites More sharing options...
keeB Posted April 17, 2009 Share Posted April 17, 2009 Thats an elegant solution, soak. Pseudo-code: <?php $q = 'select * from events where e_start = '...''; $event_dates = array(); //hold the dates of the events $result = mssql_query($q); while ($row = mysql_fetch_assoc($result)) { print_r($row); //debug, remove when not testing $event_dates[$row['e_start']] = "hi my name is keeb and i want to be your friend"; } print_r($event_dates); // debug, make sure it was populated . . . later on in mk_drawcalendar.. if(array_key_exists($row['e_start'], $event_dates)) // is e_start in event_dates?? { // YES! print "woohoo it's there!"; echo "<td class='tcell'>"; echo "<a href=\"http://www.runningprofiles.com/test2.php?month=$d-$m-$y\" rel=\"facebox\" onClick=\"document.f.eventdate.value='$m-$d-$y';\">$d</a>"; echo "</td>\n"; } else { print "crap there's no event "; echo "<td class='tcell'>"; echo "$d"; echo "</td>\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/154485-solved-finding-results-from-a-row/#findComment-812694 Share on other sites More sharing options...
runnerjp Posted April 17, 2009 Author Share Posted April 17, 2009 sorry im a little lost here what would my $q = 'select * from events where e_start = '...''; be?? $event_dates = array(); //hold the dates of the events this is from my db so do you mean echo results? Quote Link to comment https://forums.phpfreaks.com/topic/154485-solved-finding-results-from-a-row/#findComment-812766 Share on other sites More sharing options...
keeB Posted April 18, 2009 Share Posted April 18, 2009 Is this issue solved now? Quote Link to comment https://forums.phpfreaks.com/topic/154485-solved-finding-results-from-a-row/#findComment-812901 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.