3

I was trying to implement 3 dependent drop downs in my code. But was unable to retrieve dates from my ColdFusion component. Here is the code in my .cfm template:

1st drop down

<cfselect name="city_code"  class="styled-select"
                bind="cfc:getcity.getcity1()"
                bindonload="true" >

2nd drop down

<cfselect name="movie_id" class="styled-select" 
               bind="cfc:getcm.getmovies({city_code})">
</cfselect>

3rd drop down

  <cfselect id="movie_id1" name="movie_id1" 
              class="styled-select" 
              bind="cfc:getcm.getdate({movie_id})"/>

In the 3rd drop down, I want to display dates for about five days from the current date. Here is my cfc code:

 <cfset var data="">
 <cfset var result=ArrayNew(2)>
 <cfset var i=0>

 <cfquery name="data2" datasource="sqldb">
     select movie_id,release_date 
     from shows
     where movie_id = '#ARGUMENTS.movie_id#'

 </cfquery>
  <cfset result[1][1] = "0"> 
<cfset result[1][2] = " Select Date"> 

 <cfloop index="i" from="1" to="#data2.recordcount#">
      <cfset result[i+1][1]=data2.movie_id[i]>
    <cfset result[i+1][2]=data2.release_date[i]>
     </cfloop>
<cfreturn result>

This CFC is working for me, but I have to retrieve 5 dates before release date.

Leigh
  • 28,765
  • 10
  • 55
  • 103
muralee
  • 43
  • 4
  • 2
    So what breaks? When you opened up your browser dev tools, did you see something in the Ajax response? – Raymond Camden Aug 20 '13 at 11:20
  • 1
    Can we see some of the code from your CFC? – Scott Stroz Aug 20 '13 at 11:33
  • 1
    Can you successfully run those cfc functions without binding them to a form control? – Dan Bracuk Aug 20 '13 at 11:57
  • There's insufficient info to go on here. Do you get JS errors? Are the CFCs returning what's expected? Are they being hit at all? What happens if you call your remote functions via the browser rather than via JS: do they return what you expect? What troubleshooting have you actually already done (so we can eliminate that from our suggestions)? – Adam Cameron Aug 20 '13 at 12:00
  • 7
    On a side note, you may want to reconsider the use of ``. Using the built in client side functionality of ColdFUsion is wonky at best. By using this functionality, you kind of paint yourself into a corner and pigeonhole your talents. Learn how to do this with a plain old ` – Scott Stroz Aug 20 '13 at 12:07
  • @ScottStroz i have attached the cfc you have been asking. – muralee Aug 20 '13 at 12:52
  • @ScottStroz yes i have also tried with select tag but the problem is i'm unable to fetch the data based on the selection made in previous drop down list. – muralee Aug 20 '13 at 12:57
  • 1
    You say the 'CFC is working', what do you mean by that? Is it returning values - but just not the ones you want? You will need to spruce up your query to get the next 5 dates. First, use `` for the movie ID - it will save you some headaches. Second, you will need to order your results with an `ORDER BY` clause - such as 'ORDER BY release_date`. Third, yoiu will need to use whatever clause your SQL engine supports to limit the number of results - `TOP n` for SQL server, `LIMIT` for MySQL, etc. Lastly, not sure a 2 dimensional array is the best format for this data. – Scott Stroz Aug 20 '13 at 13:17
  • 3
    User - again - what are you seeing in the browser? If you do not know how to use your browser tools to debug AJAX issues, then you really need to learn them. The information there can help us to help you. If you are using Chrome, open the Dev Tools, go to the Network monitor, and you should see the XHR request. – Raymond Camden Aug 20 '13 at 14:01
  • @ScottStroz all functionality is working perfectly but i want some extra logic on third dropdown,in this i have only release_date but i want to display 5 previous dates to release_date for movie ticket booking. – muralee Aug 21 '13 at 04:53
  • If all the functionality was working perfectly, we would not be having this discussion. Your question is not clear though, are you getting data returned but want to know how to massage it? Or are you not getting data back at all? I still think the best way to handle this is by updating your query, using my suggestion above, to only pull back the values you want to return. – Scott Stroz Aug 21 '13 at 11:26

1 Answers1

0

k try this way murali

 <cfquery name="data2" datasource="bookonline">
           select tid,daysb4booking
           from shows
           where movie_id = '#ARGUMENTS.movie_id#'
         </cfquery>
      <cfset arr=ArrayNew(1)>
           <cfloop index="i" from="1" to="#data2.recordcount#">
           <cfset arr[i]=data2.daysb4booking[i]>
           </cfloop>
           <cfset num=#LSNumberFormat(arraymax(arr))#>
           <cfset result[1][1] = "0"> 
           <cfset result[1][2] = " Select Date"> 
    <!--- convert results to array--->
    <cfloop index="i" from="1" to="#num#">
           <cfset result[2][1]=data2.tid[1]>
           <cfset result[2][2]=dateformat(dateadd("d",i,now()))>
    </cfloop>
Umesh Varma
  • 94
  • 1
  • 9
  • -1. That does not generate five dates. The loop overwrites the array values on each iteration. It is also inefficient (extraneous loops, functions, pound signs, lack of cfqueryparam). – Leigh Sep 13 '13 at 01:23