krausehaus2 Posted October 5, 2006 Share Posted October 5, 2006 I am creating a special events calendar in a web site for a local church. I have the calendar already created, (hopefully the correct way), but when I query MSSQL I am only able to have the last event put into the calendar. I have tried to put the query for the database almost everywhere in the code. The only way I can get all three events in the calendar is to have three calendars show up.. lol.. If anyone can point me the correct way it would be very much appreciated. Here is what I have coded.. I have the query commented out so the calendar works. I am using and incDB page to connect to the database.Thanksif ($numerical_month == 10){ $days = 1; for($a = 1; $a <= $weeks_in_month; $a++) { for($x = 1; $x <= 1; $x++) { print " <tr>"; for ($i = 1;$i <= $days_in_week; $i++) {// if ($results)// { // while ($row = mssql_fetch_array($results))// {// $calendar_date = $row["calendar_date"];// $special_event = $row["special_event"];// $calendar_month = substr($calendar_date, 0, 2);// $calendar_day = substr($calendar_date, 3, 2);// if ($calendar_month == $numerical_month)// {// if ($calendar_day == $days)// {// print "$special_event";// }// } if ($days <= 0) { print "<td>"; print "--------"; print "</td>"; $days++; } elseif ($days > $days_in_month) { print "<td align=\"center\">"; print "--------"; print "</td>"; $days++; } else { print "<td align=\"left\" valign=\"top\">"; print "$days<br>"; print "</td>"; $days++; } } print " </tr>";// } //close while// } // close if// } // close for } // close for } // close for} // close if Quote Link to comment https://forums.phpfreaks.com/topic/23049-help-calendar-problems-using-mssql/ Share on other sites More sharing options...
Hi I Am Timbo Posted October 5, 2006 Share Posted October 5, 2006 You would want to mssql_fetch_row instead. You are getting the whole result, so it only executes the loop once. Quote Link to comment https://forums.phpfreaks.com/topic/23049-help-calendar-problems-using-mssql/#findComment-104105 Share on other sites More sharing options...
krausehaus2 Posted October 5, 2006 Author Share Posted October 5, 2006 If I use that will it not just get the first event from the database? Or will it go for the next event everytime it loops? Quote Link to comment https://forums.phpfreaks.com/topic/23049-help-calendar-problems-using-mssql/#findComment-104115 Share on other sites More sharing options...
Hi I Am Timbo Posted October 5, 2006 Share Posted October 5, 2006 No, it gets the next row. Here is a very short and good explanation of what is going on.http://www-eleves-isia.cma.fr/documentation/PhpDoc/function.mssql-fetch-row.html Quote Link to comment https://forums.phpfreaks.com/topic/23049-help-calendar-problems-using-mssql/#findComment-104116 Share on other sites More sharing options...
krausehaus2 Posted October 5, 2006 Author Share Posted October 5, 2006 I tried to have it pull up from the rows function but I still have to run the query using a for loop. Am i going the wrong way with my calendar? Quote Link to comment https://forums.phpfreaks.com/topic/23049-help-calendar-problems-using-mssql/#findComment-104262 Share on other sites More sharing options...
Hi I Am Timbo Posted October 5, 2006 Share Posted October 5, 2006 what is this: for($x = 1; $x <= 1; $x++)?Are you doing this for one month at a time? Are there more than one event on every day?How about executing one query for each day of the month. Sure, it may take 3 or 4 seconds, but it would be really easy to do right? Quote Link to comment https://forums.phpfreaks.com/topic/23049-help-calendar-problems-using-mssql/#findComment-104275 Share on other sites More sharing options...
krausehaus2 Posted October 5, 2006 Author Share Posted October 5, 2006 yes the calendar is for one month. Querying per day wouldn't be so bad. The only problem with that is where I live most people are on dialup. I live in the high mtns of NC and most people cannot get DSL, broadband, etc. I'm gonna give it a shot though. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/23049-help-calendar-problems-using-mssql/#findComment-104284 Share on other sites More sharing options...
Barand Posted October 5, 2006 Share Posted October 5, 2006 Perhaps you could tell us what the code is [b]supposed[/b] to do.Are you storing a record for every day in the table, or just for those days that have an event? Quote Link to comment https://forums.phpfreaks.com/topic/23049-help-calendar-problems-using-mssql/#findComment-104387 Share on other sites More sharing options...
krausehaus2 Posted October 5, 2006 Author Share Posted October 5, 2006 I am storing the event for only the days that they are on. The problem is that the query to the database has to be done in a loop so it only shows the very last event from the database. Quote Link to comment https://forums.phpfreaks.com/topic/23049-help-calendar-problems-using-mssql/#findComment-104451 Share on other sites More sharing options...
Barand Posted October 5, 2006 Share Posted October 5, 2006 If you only want the last event[code]SELECT ...whatever ..... FROM tablenameORDER BY calendar_date DESC LIMIT 1[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23049-help-calendar-problems-using-mssql/#findComment-104477 Share on other sites More sharing options...
krausehaus2 Posted October 5, 2006 Author Share Posted October 5, 2006 The perfect world would be where I could query the database in the for loop and have it only do one row from the database each time it ran through the loop. The next line from the database that is... Quote Link to comment https://forums.phpfreaks.com/topic/23049-help-calendar-problems-using-mssql/#findComment-104501 Share on other sites More sharing options...
krausehaus2 Posted October 6, 2006 Author Share Posted October 6, 2006 Okay!! I got it working in the calendar!! woot!! But one problem.. Or should I say 5 problems. I am getting 5 error messages at the bottom of the page. PHP Notice: Undefined variable: event_date in E:\WebSites\TrcOnline\paul\concord_baptist\calendar_of_events.php on line 480. Line 480 states if ($results). This is for the query to the database. If anyone can see why it would be greatly appreciated. I think it might be for the 5 <tr>'s.Here's the code:if ($numerical_month == 10){ $days = 1; for($a = 1; $a <= $weeks_in_month; $a++) { for($x = 1; $x <= 1; $x++) { print " <tr>"; for ($i = 1;$i <= $days_in_week; $i++) { if ($days <= 0) { print "<td>"; print "--------"; print "</td>"; $days++; } if ($days > $days_in_month) { print "<td align=\"center\">"; print "--------"; print "</td>"; $days++; } else { $results = mssql_query("Select event_date, special_event from event_calendar where event_date = $days;", $connection); if ($results) <---- here it is { while ($row = mssql_fetch_array($results)) { $event_date = $row["event_date"]; $special_event = $row["special_event"]; } if ($event_date != $days) { print "<td align=\"left\" valign=\"top\">"; print "$days"; } else { print "<td align=\"left\" valign=\"top\">"; print "$days<br>"; print "$special_event"; } print "</td>"; $days++; } } } print " </tr>"; } }} Quote Link to comment https://forums.phpfreaks.com/topic/23049-help-calendar-problems-using-mssql/#findComment-104746 Share on other sites More sharing options...
krausehaus2 Posted October 6, 2006 Author Share Posted October 6, 2006 ;D I found my error!! Instead of having an if statement to see if the variable from the query is != to $days I changed it to if(empty($special_event)!! Woot!! Thanks for all who helped.. :D Quote Link to comment https://forums.phpfreaks.com/topic/23049-help-calendar-problems-using-mssql/#findComment-104790 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.