Jump to content

Archived

This topic is now archived and is closed to further replies.

krausehaus2

HELP!! Calendar problems using MSSQL

Recommended Posts

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.

Thanks

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 ($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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
If you only want the last event
[code]
SELECT ...whatever ..... FROM tablename
ORDER BY calendar_date DESC LIMIT 1

[/code]

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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>";
      }
  }
}
 

Share this post


Link to post
Share on other sites
;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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.