Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/23049-help-calendar-problems-using-mssql/
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?
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!
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>";
      }
  }
}
 
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.