3 Replies Latest reply on Jul 8, 2009 1:47 PM by CFmonger

    mini-Calendar not passing proper ID's

    CFmonger

      Hello;

      I have posted about this little calendar before. But then, I didn't have anything really working, now, I actually have it passing the proper dates from the db and making links in the day an event falls on.... BUT it passes the same ID to all the days in the month instead of the ID or the record it is pulling from.Can anyone help me figure out what I need to add to this to make it separate out the proper ID to link to another dynamic page? I believe it is either my query, or I need to make a cfset that makes the day eq ID or something. I'm not sure and not sure how to write that.
      Here is my code:

       

      <cfoutput>

      <table border="1" width="100%" cellpadding="0" cellspacing="0">
        <tr>
        <cfloop index="x" from="1" to="7">
              <!--- Change the days of the week to be shorter--->
                  <td><FONT face="Arial, Helvetica, sans-serif" color="##000000" size="2">#DateFormat(x, "ddd")#</FONT></td>
              </cfloop>
              </tr>
      </cfoutput>

      <cfset firstOfTheMonth = createDate(year(now()), month(now()), 1)>
      <!--- Add new variable for the end of the month--->
      <cfset endOfTheMonth = createdatetime(year(now()), month(now()), #daysinmonth(firstOfTheMonth)#, 23, 59, 59)>

      <!--- Query the database and search between the start and end--->
      <CFQUERY datasource="#APPLICATION.dataSource#" Name="get_dates">
          Select ID, eventDate, Day(eventDate) AS dd
          From events
      Where eventDate Between #firstOfTheMonth# and #endOfTheMonth#
      </CFQUERY>

      <!--- set the day from the list in the db--->
      <cfset day = ValueList(get_dates.dd)>

      <!---<cfoutput>#day#</cfoutput>--->

      <cfset dow = dayofWeek(firstOfTheMonth)>
      <cfset pad = dow - 1>

      <cfoutput>
          <tr>
      </cfoutput>

      <cfif pad gt 0>
          <cfoutput>
              <td colspan="#pad#"> </td>
          </cfoutput>
      </cfif>

      <cfset days = daysInMonth(now())>
      <cfset counter = pad + 1>
      <cfloop index="x" from="1" to="#days#">
          <cfif x is day(now())>
              <cfoutput><td bgcolor="##f1f09c"></cfoutput>
          <cfelse>
              <cfoutput><td></cfoutput>
          </cfif>

          <cfoutput>
          <!--- Here we compare the day list to the days being outputed if there is a match we link it.--->
          <cfif x is day(now())>
              <cfif listFind(day,x)>
                  <a href="/detail.cfm?dd=#get_dates.ID#" class="dateNav"><b>[#x#]</b></a>
        <cfelse>
         <FONT face="Arial, Helvetica, sans-serif" color="##000000" size="2"><b>#x#</b></FONT>
        </cfif>
          <cfelse>
              <cfif listFind(day,x)>
                  <a href="/detail.cfm?dd=#get_dates.ID#" class="dateNav"><b>[#x#]</b></a>
              <cfelse>
                  <FONT face="Arial, Helvetica, sans-serif" color="##000000" size="2">#x#</FONT>
              </cfif>
          </cfif>
          </td>
      </cfoutput>
      <cfset counter = counter + 1>
      <cfif counter is 8>
          <cfoutput></tr></cfoutput>
          <cfif x lt days>
              <cfset counter = 1>
              <cfoutput>
                  <tr>
              </cfoutput>
          </cfif>
      </cfif>
      </cfloop>

      <cfif counter is not 8>
          <cfset endPad = 8 - counter>
          <cfoutput>
              <td colspan="#endPad#"> </td>
          </cfoutput>
      </cfif>

      <cfoutput>
      </table>
      </cfoutput>

       

      I know this is a lot of code. The problem is from my query down. Really everything before that is working, it is just not passing proper ID's to the proper records. They all have the same ID.

      Can anyone help me?

      Thank you

       

      CFmonger

        • 1. Re: mini-Calendar not passing proper ID's
          Dan Bracuk Level 5

          I find life to be easier when I do my logic first and formatting second.  Much of your 'a lot of code to read' is formatting and gets in the way of problem solving.

           

          Step 1.  Comment out all your code after your query and cfdump it to verify it's giving you what you want.

          Step 2   Start putting in your output logic.  Do this one piece at a time.  Don't worry about tables or colours or anything else.  Once a logic block has been deemed to be not the problem, don't change it.

           

          Continue until you see what piece of code produces the wrong answer.

          • 2. Re: mini-Calendar not passing proper ID's
            CFmonger Level 1

            This is the code doing the wrong thing:

             

            <cfset firstOfTheMonth = createDate(year(now()), month(now()), 1)>

            <!--- Add new variable for the end of the month--->
            <cfset endOfTheMonth = createdatetime(year(now()), month(now()), #daysinmonth(firstOfTheMonth)#, 23, 59, 59)>

             

            <!--- Query the database and search between the start and end--->
            <CFQUERY datasource="#APPLICATION.dataSource#" Name="get_dates">
                Select ID, eventDate, Day(eventDate) AS dd
                From events
            Where eventDate Between #firstOfTheMonth# and #endOfTheMonth#
            </CFQUERY>

            <!--- set the day from the list in the db--->
            <cfset day = ValueList(get_dates.dd)>

             

            <cfoutput>
                <!--- Here we compare the day list to the days being outputed if there is a match we link it.--->
                <cfif x is day(now())>
                    <cfif listFind(day,x)>
                        <a href="/detail.cfm?ID=#get_dates.ID#" class="dateNav"><b>[#x#]</b></a>
              <cfelse>
               <FONT face="Arial, Helvetica, sans-serif" color="##000000" size="2"><b>#x#</b></FONT>
              </cfif>
                <cfelse>
                    <cfif listFind(day,x)>
                        <a href="/detail.cfm?ID=#get_dates.ID#" class="dateNav"><b>[#x#]</b></a>
                    <cfelse>
                        <FONT face="Arial, Helvetica, sans-serif" color="##000000" size="2">#x#</FONT>
                    </cfif>
                </cfif>
                </td>
            </cfoutput>

             

            Like I said, it is passing the proper day of the month, because it makes a link on the proper date, it is not passing the proper id to go with the record for the respective date.

             

            CFmonger

            • 3. Re: mini-Calendar not passing proper ID's
              CFmonger Level 1

              Can anyone help me with this?

              I just need to pass a list of ID's that match the event dates and calendar dates.I believe that is the solution I am looking for here, but I don't know how to write it.

               

              Can someone please help me out?