|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
I think the title says it all.
I have a query that I want to run. At this point, CFLOOP doesn't seem to be an option. I want to execute the query, and if it meets a certain condition, I want it to go to the next record in the query. Code:
<CFQUERY name=query1> SELECT * FROM QueryTable1 </CFQUERY> <CFQUERY name=query2> SELECT * FROM QueryTable2 </CFQUERY> <CFLOOP query=query1> blah blah blah <CFIF query.condition>"next record in query2"</CFIF> </CFLOOP> Or something like that. Thanks in advance! |
|
#2
|
|||
|
|||
|
Quote:
You can use ifstatements. Both in your query and outside of it to excute your querys. <cftransaction> <cfif blah IS "blah"> <cfquery> SELECT BLAH1 FROM BLAH1 AND BLAH2 </cfquery> <cfif blah2 IS NOT blah1> <cfquery> SELECT BLAH1 FROM BLAH2 and BLAH3 </cfquery> </cfif> </cfif> |
|
#3
|
|||
|
|||
|
Quote:
From my previous post, the <CFLOOP query=query1> tag is necessary. So I'm really confused now. |
|
#4
|
|||
|
|||
|
Quote:
I'm unsure what you are trying to do. Loop over one query and if it meets some condition go to the next record in another query? I've never heard of such a thing and can't envision why you'd take this route. I can't tell if this is a situation where you really should combine the queries into one, or whether it's something you can do by looping over one or the other of the queries if they truly need to be separate (which from past experience I highly doubt). Please explain in more detail what exactly you are trying to do.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#5
|
|||
|
|||
|
I hope I can explain this correctly. I've got a list of items in a database table(Items).
The fields that would be involved would be Itemname, Image, Group, SortOrder. Group and SortOrder determines in what order the items would appear. The Group field would take precedence over the SortOrder field. If the list is at the end of a group, then a <hr> is inserted (to show the division between possible groups and the rest of the items without a group). However, in my listing, I have an option from another table that allows for a value to be inserted for Columns. This option basically lets me set how many columns would appear in the listing (basically a dynamic table). I have it to where the list would list from top/bottom, as opposed to left/right. Code:
<!--If the Columns value is set to '2' --> <table><tr><td> <table>Item1</table> <table>Item2</table> </td></tr><tr><td> <table>Item3</table> <table>Item4</table> <table>Item5</table> </td></tr></table> In a group, I want it to appear as such: Code:
<!--If the Columns value is set to '2' --> <table><tr><td> <table>Item10(group1)</table> <table>Item11(group1)</table> </td></tr><tr><td> <table>Item12(group1)</table> <table>Item13(group1)</table> </td></tr></table> <hr> <table><tr><td> <table>Item1</table> <table>Item2</table> </td></tr><tr><td> <table>Item3</table> <table>Item4</table> <table>Item5</table> </td></tr></table> The reason I'm trying to create two querys: One is to get the complete listing on the Items table. SELECT * FROM Items Order by Group, SortOrder Two is to get the count of a certain group. SELECT `group`, Count(*) as Kount FROM Items GROUP BY `group` If the recordcount of the first query exceeds the Kount value of the 2nd query, I want the next row of the 2nd query. |
|
#6
|
|||
|
|||
|
I'm still not convinced that you can't do this with a single query and the proper aggregate functions. However, you could also do this by looping over the main query and calculating the group counts (omitting the second query), or you could use the query of queries functionality to run query against the existing query result set to determine the counts. Another option would be to take the second query and turn it into a structure that you could then use to look up the group count for any given group.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > ColdFusion alternative to ASP's movenext |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|