Jump to content


Photo

HELP!! Calendar problems using MSSQL


  • Please log in to reply
12 replies to this topic

#1 krausehaus2

krausehaus2
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 05 October 2006 - 02:46 AM

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


#2 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 05 October 2006 - 02:50 AM

You would want to mssql_fetch_row instead.  You are getting the whole result, so it only executes the loop once.

#3 krausehaus2

krausehaus2
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 05 October 2006 - 03:18 AM

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?

#4 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 05 October 2006 - 03:21 AM

No, it gets the next row.  Here is a very short and good explanation of what is going on.

http://www-eleves-is...-fetch-row.html

#5 krausehaus2

krausehaus2
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 05 October 2006 - 03:24 PM

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?

#6 Hi I Am Timbo

Hi I Am Timbo
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 05 October 2006 - 03:45 PM

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?

#7 krausehaus2

krausehaus2
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 05 October 2006 - 03:52 PM

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!

#8 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 05 October 2006 - 05:29 PM

Perhaps you could tell us what the code is supposed to do.

Are you storing a record for every day in the table, or just for those days that have an event?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#9 krausehaus2

krausehaus2
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 05 October 2006 - 06:40 PM

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.

#10 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 05 October 2006 - 07:09 PM

If you only want the last event
SELECT ...whatever ..... FROM tablename
ORDER BY calendar_date DESC LIMIT 1


If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#11 krausehaus2

krausehaus2
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 05 October 2006 - 07:25 PM

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...

#12 krausehaus2

krausehaus2
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 06 October 2006 - 01:16 AM

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>";
      }
  }
}
 

#13 krausehaus2

krausehaus2
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 06 October 2006 - 03:32 AM

;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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users