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

Using SQL within cfscript

New Here ,
May 10, 2009 May 10, 2009

Copy link to clipboard

Copied

Hey everyone,

I am using the cfscript I got for a calendar from this website: http://www.drisgill.com/files/cal.txt

Its fairly straight forward and displayed a generic plain calendar for the month.  I am trying to make it so the calendar fills dynamically with information I pull from a database.  So essentially, as the calendar adds days I want it to see if that date equals the date I have in the DB, if it does then it would display simple text like, "Event."

This is the code that loops through and creates the calendar, keep in my this is cfscript

// loop thru all the dates in this month
     for (i=1; i lte DaysInMonth(firstDay); i = i+1) {
          //is it Sunday? if so start new row.
          if (DayOfWeek(CreateDate(curYear, curMonth, i)) eq 1) {
               outString = outString & "<tr>";
          }
          // insert a day
          outString = outString & "<td align='left' valign='top' width='#width#px' ";
          if(CreateDate(curYear, curMonth, i) eq CreateDate(year(now()),month(now()),day(now()))){
               outString = outString & "class='day-current'";
          }else{
               outString = outString & "style='background-color: whitesmoke' ";
          }
          outString = outString & "height='#height#'>#i#<br></td> ";

I realize that last line is where I need my output to go but for the life of me I cant get any queries to run or compare in cfscript.  I am fairly new to cfscript.

Any help would be greatly appreciated!!
Thanks!
TOPICS
Advanced techniques

Views

832

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
Guru ,
May 10, 2009 May 10, 2009

Copy link to clipboard

Copied

You could create the outStringin a standard "way" using cfset and then

output it cfoutput.

Sincerely,

Michael

El 10/05/2009, a las 16:13, davella <forums@adobe.com> escribió:

>

Hey everyone,

>

I am using the cfscript I got for a calendar from this website: http://www.drisgill.com/files/cal.txt

>

Its fairly straight forward and displayed a generic plain calendar

for the month. I am trying to make it so the calendar fills

dynamically with information I pull from a database. So

essentially, as the calendar adds days I want it to see if that date

equals the date I have in the DB, if it does then it would display

simple text like, "Event."

>

This is the code that loops through and creates the calendar, keep

in my this is cfscript

>

// loop thru all the dates in this month

for (i=1; i lte DaysInMonth(firstDay); i = i+1) {

//is it Sunday? if so start new row.

if (DayOfWeek(CreateDate(curYear, curMonth, i)) eq 1) {

&n bsp; outString = outString & "<tr>";

}

// insert a day

outString = outString & "<td align='left' valign='top'

width='#width#px' ";

if(CreateDate(curYea r, curMonth, i) eq

CreateDate(year(now()),month(now()),day(now()))){

&n bsp; outString = outString & "class='day-current'";

}else{

&n bsp; outString = outString & "style='background-

color: whitesmoke' ";

}

outString = outString & "height='#height#'>#i#<br></td> ";

>

I realize that last line is where I need my output to go but for the

life of me I cant get any queries to run or compare in cfscript. I

am fairly new to cfscript.

>

Any help would be greatly appreciated!!

Thanks

>

>

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
Valorous Hero ,
May 11, 2009 May 11, 2009

Copy link to clipboard

Copied

LATEST

First of all <cfscript></cfscript> is nothing special.  It is just a style choice.  All that code can be rewritting with corresponding <cftag> based syntax such as <cfloop...> and <cfif> and it would work exactly the same.

Secondly.  You can not yet do a query directly in <cfscript> but you can easily call a User Defined Function that does the query for you.

Thirdly.  That is probably not the best solution.  One does not usually want to do a query over and over inside a loop like that.  It can be very poor performance.  The better solution is usually to do one query to get all the data and then use the returned record set or some other data structure based on it on the returned record set inside the loop.

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