timmah1 Posted December 6, 2008 Share Posted December 6, 2008 I have an event calendar script. I have a database that pulls information from the database and display's the info on the appropriate day. Well, that's what is suppose to happen. The problem is, it's only showing the last event in the database. Right now, I have 4 events in the database and this is only showing the last one, which is December 31, 2008 $title = 'December'; $year = date("Y"); $day_num = 1; $sql="SELECT * FROM events WHERE month = '$title' AND year = '$year'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ if($day_num == $row['day']) { $show = "Gotcha"; } else { $show = "Nope"; } } $day_num++; Can anybody tell me why? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted December 6, 2008 Share Posted December 6, 2008 You're incrementing $day_num outside of the while loop. Quote Link to comment Share on other sites More sharing options...
timmah1 Posted December 6, 2008 Author Share Posted December 6, 2008 I was trying to avoid putting the entire code here, but the $day_num is inside the loop <?php $date =time () ; $today = date('d') ; $day = date('d', $date) ; $month = date('m', $date) ; $year = date('Y', $date) ; $first_day = mktime(0,0,0,$month, 1, $year) ; $title = date('F', $first_day) ; $day_of_week = date('D', $first_day) ; switch($day_of_week){ case "Sun": $blank = 0; break; case "Mon": $blank = 1; break; case "Tue": $blank = 2; break; case "Wed": $blank = 3; break; case "Thu": $blank = 4; break; case "Fri": $blank = 5; break; case "Sat": $blank = 6; break; } $days_in_month = cal_days_in_month(0, $month, $year) ; ?> <div align="center"><h2><?=$title;?> <?=$year;?></h2></div> <table width=100% border=1 cellpadding="6" cellspacing="0" bordercolor="#f7c700"> <tr> <td width="14%" align="center" valign="top" bgcolor="#f7c700"><strong>Sunday</strong></td> <td width="14%" align="center" valign="top" bgcolor="#f7c700"><strong>Monday</strong></td> <td width="14%" align="center" valign="top" bgcolor="#f7c700"><strong>Tuesday</strong></td> <td width="16%" align="center" valign="top" bgcolor="#f7c700"><strong>Wednesday</strong></td> <td width="14%" align="center" valign="top" bgcolor="#f7c700"><strong>Thursday</strong></td> <td width="14%" align="center" valign="top" bgcolor="#f7c700"><strong>Friday</strong></td> <td width="14%" align="center" valign="top" bgcolor="#f7c700"><strong>Saturday</strong></td> </tr> <?php $day_count = 1; ?> <tr> <?php while ( $blank > 0 ) { ?> <td align="left" valign="top" bordercolor="#f7c700"></td> <?php $blank = $blank-1; $day_count++; } $day_num = 1; while ( $day_num <= $days_in_month ) { if($day_num == $today) { $bg = "#a78127"; } else { $bg = "#fffff"; } $sql="SELECT * FROM events WHERE month = '$title' AND year = '$year'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ if($day_num == $row['day']) { $show = "Gotcha"; } else { $show = "Nope"; } } ?> <td height="75" align="left" valign="top" bgcolor="<?=$bg;?>"><?=$day_num;?><br /><?=$show;?><br /></td> <?php $day_num++; $day_count++; if ($day_count > 7) { ?></tr><tr> <?php $day_count = 1; } } while ( $day_count >1 && $day_count <=7 ) { ?> <td> </td> <?php $day_count++; } ?> </tr></table> This is the entire code for the calendar 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.