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

Looping while a condition is true and ignoring false ones

Explorer ,
May 21, 2008 May 21, 2008
I'm having some difficultly understanding how to program a loop that checks whether a string value is TRUE. And if its not TRUE, I want it to start again until it gets a TRUE response.

So what I mean is - I am reading in a XML file from a standard URL. I then use <cfset> to put the information into a variable. However I only want to put it into the variable if an element called STATUS is "OK". If its not "OK", then I want it to read more files in until it hits one where the STATUS is "OK".

Heres my code thus far:

<cfhttp url=" http://www.xxx.com?Name=#RandName#&PartNumber=#RandPartNo#">
<cfset xItem = xmlparse(cfhttp.FileContent)>
<cfif #xItem.XXXFeed.product.STATUS.xmltext# IS "OK">
<cfset Item = xItem.HDSFeed.product.item>

So as you can see above, the URL from which the data is coming from is generated using random names and part numbers. So each time you refresh the page (using F5), it will return different information. It then checks to see if the STATUS atttribute contains text that says "OK". If it is indeed "OK", then we can create the variable "Item". If the text IS NOT "OK" then I want it to basically refresh itself until it does retireve a URL which contains STATUS as "OK".

Any idea how this achieved? The variables #RandName# and #RandPartNo# are generated from a database query on the same page of course. Hence the need to refresh the whole page.
TOPICS
Getting started
334
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
LEGEND ,
May 21, 2008 May 21, 2008
LATEST
I am not sure if you just need a simple if branch or a while loop.

First Idea:
<cfif something.status IS NOT 'OK'>
<!--- refresh page --->
</cfif>

Second Idea:
<cfloop condition="something.status IS NOT 'OK'">
<!--- do something that changes something.status
i.e. rerun the query and fetch the xml again. --->
</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
Resources