• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

mini-Calendar not passing proper ID's

Participant ,
Jul 07, 2009 Jul 07, 2009

Copy link to clipboard

Copied

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

TOPICS
Advanced techniques

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 07, 2009 Jul 07, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 07, 2009 Jul 07, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 08, 2009 Jul 08, 2009

Copy link to clipboard

Copied

LATEST

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation