?
Solved

Help with repeating a record based on a date.

Posted on 2002-03-27
13
Medium Priority
?
251 Views
Last Modified: 2013-12-24
Hi all,

I need help making an entry in my CF calendar program repeat.  

What I want to do is offer the customer the option of selecting an option in the add form that would repeat all the fields of the add form for Monday thru Friday of each week of the month.

I will be happy to provide my code so you may interegate, if needed.

Anyone have any ideas on how I can accomplish this?
0
Comment
Question by:g118481
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
13 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 6899850
like if repeat is checked.. then loop through M-F and add it to your calendar DB?

CJ
0
 
LVL 1

Author Comment

by:g118481
ID: 6899869
Yes.
I think the difficulty of this task is how to calculate the new date for each new record.

Now, I know I want the form fields to be exactly the same, however, I really don't know how to repricate each new record with the next date in the week.

Maybe it would be better if my new code would just repricate the remainder of the current week only.
(my reference to week applies to Monday - Friday only)
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6899895
Do you want it to repeat continuously (over next x weeks) or JUST the current week.
0
Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

 
LVL 1

Author Comment

by:g118481
ID: 6899934
Would it be difficult for the code to repeat the selected event for one month at a time?

If not, then I would like that, else it shouldn't repeat for more than a single year at a time so the db doesn't grow too large at one time.  Also, there has to be some kind of limit, less the code goes into an infinite loop, right?

Thanks
0
 
LVL 1

Author Comment

by:g118481
ID: 6902530
Cheekycj,

any help you offer would be very much appreciated.
0
 
LVL 3

Expert Comment

by:winningl
ID: 6902694

Can you post some of your code?

I'm not sure what you want. Do you mean to loop through M to F and add the same form data into DB? What's the primary key in your table?

winningl
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6902785
winning! I think that is exactly what he wants.

sorta like:

<!--- Assuming VARIABLES.startDate is the start Date --->
<!--- init loop start for first week --->
<cfif DayOfWeek(VARIABLES.startDate) EQ 1>
     <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
<cfelseif DayOfWeek(VARIABLES.startDate) EQ 7>
     <cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
</cfif>
<cfset VARIABLES.loopStart = DayOfWeek(VARIABLES.startDate)>
<cfloop index="i" from="#VARIABLES.loopStart#" to="6" step="1">
     <!--- Put query here to insert into DB using VARIABLES.startDate as the time --->
     <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
</cfloop>
<!--- Add 2 days to adjust for weekend --->
<cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
<!--- Now add 4 more weeks -- 1 month --->
<cfloop index="w" from="1" to="4" step="1">
     <cfloop index="d" from="2" to="6" step="1">
          <!--- Put query here to insert into DB using VARIABLES.startDate as the time --->
          <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
     </cfloop>
     <!--- Add 2 days for weekend --->
     <cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
</cfloop>
0
 
LVL 1

Author Comment

by:g118481
ID: 6903216
Thanks for the update.

How would I implement your suggested code into my add/edit form listed below.

/**************************************************/
<CFSET FIELDLIST = "FuseCalendar_ID,CalendarDate,EventDescription,Location,Email,Website,EventName,Contact,Phone,ShowTime,FuseBox_ID">


<CFIF attributes.fuseaction IS "AddEvent">
      <!--- If adding a new event, this code is run, setting each form field to empty.      --->
      <CFLOOP LIST="#fieldlist#" INDEX="counter">
            <CFSET TEMP = SETVARIABLE("#counter#", "")>
      </CFLOOP>
      <cfset time = "8:00 AM">
<CFELSEIF attributes.fuseaction IS "EditEventID">
      <!--- if the user is creating a editing a record --->
      <CFQUERY NAME="getEvent" DATASOURCE="cmrmm">
            select *
                  from event
                        where FuseCalendar_ID = #attributes.FuseCalendar_ID#
      </CFQUERY>
      
      <!--- I will now set the form field variables to the event to be edited based on the record taken from the query above.      --->
      <CFLOOP LIST="#fieldlist#" INDEX="counter">
            <CFSET TEMP = SETVARIABLE("#counter#", "#evaluate("GetEvent." & "#COUNTER#")#")>
      </CFLOOP>
      <cfset Time = "#TimeFormat(CalendarDate)#">
      
<CFELSEIF attributes.fuseaction IS "RemoveEventID">
      <!--- This code is similar to the editing of an event, but will just display the data that is about to be deleted. --->
      <CFQUERY NAME="getEvent" DATASOURCE="cmrmm">
            select *
            from event
            where FuseCalendar_ID = #attributes.FuseCalendar_ID#
      </CFQUERY>
      
      <CFLOOP LIST="#fieldlist#" INDEX="counter">
            <CFSET TEMP = SETVARIABLE("#counter#", "#evaluate("GetEvent." & "#COUNTER#")#")>
      </CFLOOP>
      
      <cfset Time = "#TimeFormat(CalendarDate)#">
</CFIF>
<blockquote></blockquote>
<html>
<head>
      <title>Alter the Event Data for the Calendar.</title>
</head>

<Body background="/release/bg_stripe.gif" rightmargin="2" leftmargin="2">

You are about to <cfif attributes.fuseaction is "AddEvent"><B>add</B> a new event to<cfelseif attributes.fuseaction is "EditEventID"><B>modify</B> an event on<cfelseif attributes.fuseaction is "RemoveEventID">remove an event on</CFIF> the Calendar.  Fill out the form below.  All fields in <FONT COLOR="#800000">red</FONT> are required.<p>

<FORM ACTION="index.cfm" METHOD="post">
      <INPUT Type="Hidden" Name="fuseaction" Value="<cfoutput>#attributes.fuseaction#Process</cfoutput>">
      
      <INPUT TYPE="HIDDEN" NAME="FuseCalendar_ID" value="<CFOUTPUT>#FuseCalendar_ID#</CFOUTPUT>">
      <TABLE border="0">

  <TR>
                <TD VALIGN="top"><FONT COLOR="800000">Event Name:</FONT> </TD>
                <TD>
                        <INPUT TYPE="text" NAME="EventName" SIZE="20" MaxSize="100"<CFOUTPUT>value="#EventName#"</CFOUTPUT>>
                  </TD>
            </TR>
            
            <TR>
                <TD VALIGN="top"><FONT COLOR="800000"></FONT> </TD>

 <TR>
                <TD VALIGN="top"><FONT COLOR="#800000">Location:</FONT> </TD>
                <TD>
                         <INPUT TYPE="text" NAME="Location" SIZE="20" MaxSize="100"<CFOUTPUT>value="#Location#"</CFOUTPUT>
                  </TD>
            </TR>

            <TR>
                <TD VALIGN="top"><FONT COLOR="800000">Date:</FONT> </TD>
                <TD>
                        <INPUT TYPE="text" NAME="CalendarDate" SIZE="20" MaxSize="100"<CFOUTPUT>value="<cfif CalendarDate NEQ "">#DateFormat(CalendarDate)#<cfelse>#DateFormat(NOW())#</CFIF>"</CFOUTPUT>>
                        <input type="hidden" Name="CalendarDate_Date" Value="The Date must be in a valid format, such as 4/27/1998">
                  </TD>
            </TR>

            

             <TR>
                <TD VALIGN="top">Time:</TD>
                <TD>
                        Show? Yes <INPUT TYPE="Radio" NAME="ShowTime" VALUE="YES" <cfif ShowTime is "YES">CHECKED</CFIF>>
                        No <INPUT TYPE="Radio" NAME="ShowTime" VALUE="NO" <cfif ShowTime NEQ "YES">CHECKED</CFIF>> Time:
                        <INPUT TYPE="text" NAME="Time" SIZE="20" MaxSize="100"<CFOUTPUT>value="#Time#"</CFOUTPUT>>
                  </TD>
            </TR>
                  
             <TR>
                <TD VALIGN="top">Contact Name:</TD>
                <TD>
                        <INPUT TYPE="text" NAME="Contact" SIZE="20" MaxSize="50"<CFOUTPUT>value="#Contact#"</CFOUTPUT>>
                  </TD>
            </TR>

             <TR>
                <TD VALIGN="top">Phone Number:</TD>
                <TD>
                        <INPUT TYPE="text" NAME="phone" SIZE="20" MaxSize="50"<CFOUTPUT>value="#phone#"</CFOUTPUT>>
                  </TD>
            </TR>

             <TR>
                <TD VALIGN="top">Email:</TD>
                <TD>
                        <INPUT TYPE="text" NAME="Email" SIZE="20" MaxSize="50"<CFOUTPUT>value="#Email#"</CFOUTPUT>>
                  </TD>
            </TR>

             <TR>
                <TD VALIGN="top">Web Site Address:</TD>
                <TD>
                        http://<INPUT TYPE="text" NAME="WebSite" SIZE="20" MaxSize="50"<CFOUTPUT>value="#WebSite#"</CFOUTPUT>>
                  </TD>
            </TR>

             <TR>
                <TD VALIGN="top"><FONT COLOR="800000">Event Description:</FONT> </TD>
                <TD>
                        <TextArea NAME="EventDescription" Cols="45" ROWS="7" Wrap=Virtual><CFOUTPUT>#EventDescription#</CFOUTPUT></textarea>
                  </TD>
            </TR>
                              
      <tr>
            <td></TD>
            <td>
                  <input type="hidden" name="FuseBox_ID" Value="999">
                  <input type="hidden" name="EventDescription_required" Value="You must provide a description for your event.">
                  <input type="hidden" name="EventName_required" Value="You must provide a name for your event.">      
                  <!--- <input type="hidden" name="Location_required" Value="You must provide a location for your event."> --->
                  <input type="hidden" name="CalendarDate_required" Value="You must provide a description for your event.">
                  <INPUT TYPE="submit" VALUE="Make It Happen">
            </TD>
      </TR>

</FORM>
      </TABLE>
</body>
</html>
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6903229
that is your form page right.. what about the page that actually inserts the info into the DB?
0
 
LVL 1

Author Comment

by:g118481
ID: 6903475
Sorry,

I should have included my action page.  Here it is.
Thanks for your time!

/****************************************************/
<cftransaction>
     <cfmodule template="act_max_id.cfm"
          datasource="cmrmm"
          tablename="event"
          primarykey="FuseCalendar_id">
               
     <cfquery name="addToCalendar" datasource="cmrmm">
          Insert Into Event
          (FuseCalendar_ID, FuseBox_ID, CalendarDate, EventDescription, location, email, Website, EventName, contact, phone, showtime)
               Values (#max_id#, #attributes.fusebox_id#, #ParseDateTime("#dateformat(attributes.CalendarDate)# #TimeFormat(attributes.Time)#")#, '#ParagraphFormat(attributes.EventDescription)#', '#attributes.location#',  '#attributes.email#', '#attributes.website#', '#attributes.eventname#', '#attributes.contact#', '#attributes.phone#', #attributes.showtime#)
     </CFQUERY>
</cftransaction>
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 300 total points
ID: 6903530
is attributes.CalendarDate the startDate?

then it would be:

<!--- Assuming VARIABLES.startDate is the start Date --->
<cfset VARIABLES.startDate = attributes.CalendarDate>
<!--- init loop start for first week --->
<cfif DayOfWeek(VARIABLES.startDate) EQ 1>
    <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
<cfelseif DayOfWeek(VARIABLES.startDate) EQ 7>
    <cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
</cfif>
<cfset VARIABLES.loopStart = DayOfWeek(VARIABLES.startDate)>
<cfloop index="i" from="#VARIABLES.loopStart#" to="6" step="1">
    <cfquery name="addToCalendar" datasource="cmrmm">
         Insert Into Event
         (FuseCalendar_ID, FuseBox_ID, CalendarDate, EventDescription, location, email, Website, EventName,
contact, phone, showtime)
              Values (#max_id#, #attributes.fusebox_id#, #ParseDateTime("#dateformat(VARIABLES.startDate)#
#TimeFormat(attributes.Time)#")#, '#ParagraphFormat(attributes.EventDescription)#', '#attributes.location#',
 '#attributes.email#', '#attributes.website#', '#attributes.eventname#', '#attributes.contact#', '#attributes.phone#',
#attributes.showtime#)
    </CFQUERY>
    <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
</cfloop>
<!--- Add 2 days to adjust for weekend --->
<cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
<!--- Now add 4 more weeks -- 1 month --->
<cfloop index="w" from="1" to="4" step="1">
    <cfloop index="d" from="2" to="6" step="1">
    <cfquery name="addToCalendar" datasource="cmrmm">
         Insert Into Event
         (FuseCalendar_ID, FuseBox_ID, CalendarDate, EventDescription, location, email, Website, EventName,
contact, phone, showtime)
              Values (#max_id#, #attributes.fusebox_id#, #ParseDateTime("#dateformat(VARIABLES.startDate)#
#TimeFormat(attributes.Time)#")#, '#ParagraphFormat(attributes.EventDescription)#', '#attributes.location#',
 '#attributes.email#', '#attributes.website#', '#attributes.eventname#', '#attributes.contact#', '#attributes.phone#',
#attributes.showtime#)
    </CFQUERY>
         <cfset VARIABLES.startDate = DateAdd("d", 1, VARIABLES.startDate)>
    </cfloop>
    <!--- Add 2 days for weekend --->
    <cfset VARIABLES.startDate = DateAdd("d", 2, VARIABLES.startDate)>
</cfloop>
0
 
LVL 1

Author Comment

by:g118481
ID: 6910309
Cheekycj,

I have tested your code, and I am not getting the results I expected.

It is writing 25 records for April (the current month now), and all are exact duplicated of eachother, including the "startdate"

How can I change the code to add the next number of the day to the startdate field?

Thanks.
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6918636
you used the above code exactly??

I am incrementing startDate which is what gets inserted.. you have to use the queries I have not the ones you have which use attributes.CalendarDate or replace it with VARIABLES.startDate.

CJ
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question