11 Replies - 1987 Views - Last Post: 04 September 2002 - 08:59 AM Rate Topic: -----

#1 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Calendar Month Splitting

Posted 27 August 2002 - 03:29 AM

I have a calendar set up, and I want to add headers for the months, but I can't figure out how to split up the results by months...

I'm using mysql to store the calendar entries.

I would like it layed out something like this:

August:

Tue 17th: an event goes here
Fri 20th: another event goes here

September:


etc.

the only thing i'm missing is the monthly headers :(

Is This A Good Question/Topic? 0
  • +

Replies To: Calendar Month Splitting

#2 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: Calendar Month Splitting

Posted 27 August 2002 - 07:33 AM

could we perhaps see the output of what your doing, i have a calendar script, but i would like to see what your's is outputting...
Was This Post Helpful? 0
  • +
  • -

#3 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Re: Calendar Month Splitting

Posted 27 August 2002 - 07:46 AM

sure, although I haven't got too many entries in the calendar yet, as it's still in testing stages.

The calendar is for somoene else as well, so it won't ever have anything useful on my site :)

the calendar :)
Was This Post Helpful? 0
  • +
  • -

#4 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: Calendar Month Splitting

Posted 27 August 2002 - 07:47 AM

oh, so it's not like a normal calendar with squares...hmmm...
Was This Post Helpful? 0
  • +
  • -

#5 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1877
  • View blog
  • Posts: 20,284
  • Joined: 17-March 01

Re: Calendar Month Splitting

Posted 27 August 2002 - 03:14 PM

How is your data formatted? Like mmddyy?

I would make an array of 12 items, the months... then loop through using a while loop to pull just data with 05 as the month (for may)
Was This Post Helpful? 0
  • +
  • -

#6 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Re: Calendar Month Splitting

Posted 31 August 2002 - 02:08 PM

hmm, I know arrays are extremely common, but I've never used them before, and after reading the php.net manual, I'm left extremely confused.

I don't have a clue where to start so a little help would be appreciated :)

btw, my dates are formatted yyyy-mm-dd in case thats helpful.
Was This Post Helpful? 0
  • +
  • -

#7 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1877
  • View blog
  • Posts: 20,284
  • Joined: 17-March 01

Re: Calendar Month Splitting

Posted 31 August 2002 - 02:19 PM

$months = array('', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

$x = 1;

while ($x <= 12) {

// This displays the month based on the array, value 0 is blank, value 1 is January, value 8 is August.
echo "$months[$x]";

// In your data, you probably have each even with a month, so you would load all your data for where the month = $x (the month we are printing)
echo "$event";


$x++;
} 


Was This Post Helpful? 0
  • +
  • -

#8 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Re: Calendar Month Splitting

Posted 31 August 2002 - 03:22 PM

well, that kinda works, but it adds the month header before every entry in that month.

How would I add the header for one month, then all the entries, then the next month?
Was This Post Helpful? 0
  • +
  • -

#9 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1877
  • View blog
  • Posts: 20,284
  • Joined: 17-March 01

Re: Calendar Month Splitting

Posted 01 September 2002 - 10:44 AM

put a while loop inside the month while loop so it loops through all the events for that month then jumps to the next month.
Was This Post Helpful? 0
  • +
  • -

#10 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Re: Calendar Month Splitting

Posted 01 September 2002 - 11:42 AM

ok, I have this code now to select and display just the dates of each event at the moment:

 $months = array('', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November',
'December');

 $x = 1;

 while($x <= 12)
{
// mysql stuff to grab events from the database
 $query = "SELECT date, link, news_id
          FROM news_content
          ORDER BY date";

 if (!($result = @ mysql_query ($query, $connection)))
   showerror();

 if (@ mysql_num_rows($result) != 0)

 while($row = mysql_fetch_array($result))
//end of mysql stuff, now formatting and displaying
  {
   $expdate = explode("-", $row["date"]);

   $date = date("d F y", mktime(11, 0, 0, $expdate[1], $expdate[2], $expdate[0] , 0));

// this line fills the variable $month with the number of the month for use when comparing with $x
   $month = date("n", mktime(11, 0, 0, $expdate[1]));

   while ($month == $x)
    {
     if ($month == $x)
     echo "$months[$x]<br><br><br>" .
          "$date <br><br>" .
          "$month<br>";

     $x++;
    }

  }
 $x++;

}



with the first $x++; in it only shows the first event from every month, and without it displays the earliest event in the calendar infinitely.

I'm not sure where to go with this...
Was This Post Helpful? 0
  • +
  • -

#11 Spider  Icon User is offline

  • Arachnid

Reputation: 2
  • View blog
  • Posts: 769
  • Joined: 10-July 02

Re: Calendar Month Splitting

Posted 04 September 2002 - 05:51 AM

*bump* ;)
Was This Post Helpful? 0
  • +
  • -

#12 noprob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 01-July 02

Re: Calendar Month Splitting

Posted 04 September 2002 - 08:59 AM

Hey Spider,

Not sure if this is part of your problem, but I had a similar issue with the nested while statements :
http://forums.dreami...d860ed285554ca3

I spent hours trying to get the nested while statements to work before finally giving up and making the second while statement a function. May be what you need to do for the script to work properly. Course I may just be way off. :P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1