Copy link to clipboard
Copied
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:
| item | Price |
|---|---|
| 12554 | 2.00 |
| 23885 | 3.50 |
| 12554 | 5.00 |
| 88544 | 2.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
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
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
You're welcome.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more