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

Looping over a list to create a url string

New Here ,
Feb 15, 2012 Feb 15, 2012

Hi All,

This should be easy for someone with a little experience but for some reason I am having problems with it.  I need to create a url string based on query results.  Basically the query results are:

itemPrice
125542.00
238853.50
125545.00
885442.47

I need to create a url string like www.something.com/index.cfm?item1=122554&item1price=2&item2=23885&item2price=3.50 etc etc (I am actually trying to just create the string and then append it onto a url.  The index needs to be included too like item1, item2 but there will be a different number of results for each order if that makes sense - like this person bought 4 items but somebody else might buy 2).

Can somebody give me a good way to do that?  I have been trying to loop over the query somehow but it isn't working for me.  I ahve also tried making it a list but no dice.  It seems like it should be so simple.

Thanks,

Red

1.8K
Translate
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

correct answers 1 Correct answer

Enthusiast , Feb 15, 2012 Feb 15, 2012

It looks like you are overwriting rather than appending to your string variable.

Take a looks at the quick sample below.  Note that I have not tested this code.

<cfset urlString="http://www.example.com/page.cfm?"> <!--- initialize the URL string --->

<cfloop query="get_cartitems"> <!--- loop over each row and add to the string --->

    <cfif get_cartitems.currentRow gt 1>

        <cfset urlString="#urlString#&"> <!--- add ampersand after first iteration --->

    </cfif>

    <cfset urlString="#urlStri

...
Translate
Enthusiast ,
Feb 15, 2012 Feb 15, 2012

Please post the code that is not working so the forum users can review it.  It is difficult to see what is going wrong with your code without seeing the code.

Translate
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
New Here ,
Feb 15, 2012 Feb 15, 2012

Thanks for replying.  I have tried this a bunch of different ways. 

This is the way it looks right now but this is after I stripped out a lot of stuff:

<cfloop query="get_cartitems">

<cfset theurl = "ID=1521745&ITEM1=#CIPRRFNBR#&AMT1=#CIPRPRC#&TYPE=350403" />

</cfloop>

I had it set up like this at one point:

<cfset itemcount 1>

<cfloop query="get_cartitems">

<cfset theurlstring eq theurlstring & "item#itemcount#" & "=" & "#CIPRRFNBR#">

<cfset itemcount = itemcount + 1>

</cfloop>

Translate
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
Community Expert ,
Feb 15, 2012 Feb 15, 2012

It would also help to know what the column names of the query are, and how they are related to the item number and price.

Translate
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
New Here ,
Feb 15, 2012 Feb 15, 2012

Hi BK.  I am not sure what you are asking.  The two column names that I am returning are CIPRRFNBR which is the item number and CIPRPRC which is the item price.  These variables need to be included in the url.

Red

Translate
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
Community Expert ,
Feb 15, 2012 Feb 15, 2012

rdaley72 wrote:

Hi BK.  I am not sure what you are asking.  The two column names that I am returning are CIPRRFNBR which is the item number and CIPRPRC which is the item price. 

Ah. Sorry, I missed that.

Translate
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
New Here ,
Feb 15, 2012 Feb 15, 2012

I have also tried this but it only gives me the last row:

<cfloop query="get_cartitems">

<cfset thestring = "item" & #get_cartitems.currentrow# & "=" & #CIPRRFNBR# & "&" & "price" & #get_cartitems.currentrow# & "=" & #CIPRPRC#>

</cfloop>

Translate
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
Enthusiast ,
Feb 15, 2012 Feb 15, 2012

It looks like you are overwriting rather than appending to your string variable.

Take a looks at the quick sample below.  Note that I have not tested this code.

<cfset urlString="http://www.example.com/page.cfm?"> <!--- initialize the URL string --->

<cfloop query="get_cartitems"> <!--- loop over each row and add to the string --->

    <cfif get_cartitems.currentRow gt 1>

        <cfset urlString="#urlString#&"> <!--- add ampersand after first iteration --->

    </cfif>

    <cfset urlString="#urlString#item#get_cartitems.currentRow#=#UrlEncodedFormat(get_cartitems.CIPRRFNBR)#">

    <!--- append price, etc ...  Note use of UrlEncodedFormat function --->

</cfloop>

Translate
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
New Here ,
Feb 15, 2012 Feb 15, 2012

Bob...that did the trick!  I also had to add the cost of each item to the url.  Since there are decimals, I am not sure what the customer is going to want to do but they must have a plan (I removed the UrlEncodedFormat function for the prices for now). 

Thank you so much!  Let me know if you have a donate link and I will buy you a beer or soda.

Red

Translate
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
Enthusiast ,
Feb 15, 2012 Feb 15, 2012
LATEST

You're welcome.

Translate
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