|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
alphabetical list
Hi everyone. I have a list of 35 categories (in an Access database), which I would like to output to a Web page, in a table, in three colums, arranged vertically. I need to close a <td> when 12 records have been displayed, or something like that... Any idea how to do this?
Thanks, E |
|
#2
|
|||
|
|||
|
Use 3 separate loops, starting and ending at the appropriate places. You might want to calculate, and then set to variables, the values for the end and beginning of each column. That way, if your data changes, your page compensates automatically.
<table> <tr> <td> <cfloop query="yourQueryName" STARTROW=1 ENDROW=#FirstColumnEnd#> <p>#yourQueryResult#</p> </cfloop> </td> <td> <cfloop query="yourQueryName" STARTROW=#SecondColumnBegin# ENDROW=#SecondColumnEnd#> <p>#yourQueryResult#</p> </cfloop> </td> <td> <cfloop query="yourQueryName" STARTROW=#ThirdColumnBegin# ENDROW=#yourQueryName.Recordcount#> <p>#yourQueryResult#</p> </cfloop> </td> </tr> </table> |
|
#3
|
|||
|
|||
|
Easy
Hi,
It's quite easy to do. You need to have a counter that has the number of columns in it. Then, inside the cfoutput you need to increment this. Then you check it and if necessary, close a row and start a new one. <cfset counter = 0> <cfoutput query="myQuery"> <cfset counter = IncrementValue(counter)> <cfswitch expression="counter"> <cfcase value="3"> </tr><tr> </cfcase> <cfcase value="6"> </tr><tr> </cfcase> <cfcase value="9"> </tr><tr> </cfcase> <cfcase value="12"> </tr><tr> </cfcase> <cfcase value="15"> </tr><tr> </cfcase> <cfcase value="18"> </tr><tr> </cfcase> <cfcase value="21"> </tr><tr> </cfcase> <cfcase value="24"> </tr><tr> </cfcase> <cfcase value="27"> </tr><tr> </cfcase> <cfcase value="30"> </tr><tr> </cfcase> <cfcase value="33"> </tr><tr> </cfcase> </cfswitch> <td>#myCategory#</td> </cfoutput> Should do the trick. |
|
#4
|
|||
|
|||
|
You can do this in just a few lines of code using the MOD operator:
Code:
<table border="1"> <cfoutput query="categoryQuery"> <cfif categoryQuery.currentRow MOD 3 EQ 1> <tr> </cfif> <td>#categoryQuery.categoryName#</td> <cfif categoryQuery.currentRow MOD 3 EQ 0> </tr> </cfif> </cfoutput> </table> |
|
#5
|
|||
|
|||
|
Thank you for the replies! Unfortunately, none of them worked :-( The one using the MOD function works in the sense that it indeed aranges records in three columns. However, this is an alphabetical list and I want the items to appear alphabetically in a vertical manner. With the MOD solution, categories such as Air Pressure, Analog Data, Cable ... appear arranged horizontally, instead of one underneath each other.
The solution regarding setting FirstColumnBegin, FirstColumnEnd, etc. variables almost worked --- the table appeared fine, I received no errors, except that the query results were not displayed. All I got was #getcategories#, which appeared 27 times, in 3 columns :-) Is there anything else that I may need to specify in the <cfloop>? The third solution, regarding the counter set did not work at all - maybe I did not understand how to implement it? All I got was one <td> with all the records in it...I placed all the code you indicated (with the exception of setting the counter) within a <tr>. Is this wrong? Thanks again. Any further ideas would be appreciated! E |
|
#6
|
|||
|
|||
|
Yes, that will be rather difficult because a table with 3 columns MUST be built from the top down, which is totally incompatible with the order that the query is returning the result set.
The two options that I could think of are modifying the SQL statement to get things into an order that allows you to output them using a table. But this will require some rather messy SQL and conditional logic in the ORDER BY clause. The second option would be to calculate what the next value should be within each loop iteration. This also seems like it would be rather messy, requiring the use of arrays or lists. I guess what I'm saying is that doing what you want is going to be quite difficult. I'm sure it's possible, but the amount of work it will take to do it might outweigh the advantage of having the order go down instead of across. Last edited by kiteless : May 17th, 2004 at 12:05 PM. |
|
#7
|
|||
|
|||
|
Quote:
Yes, there's a missing <cfoutput> that needs to be wrapped around the whole thing. Then it should work.. as long as you specify a fieldname... #getcategories.yourFieldName# |
|
#8
|
|||
|
|||
|
Quote:
|
|
#9
|
|||
|
|||
|
The solution worked perfectly! Thank you!
|
|
#10
|
||||
|
||||
|
Not to kick a dead horse but, i would use inline frames then do three simple queries, but then again i still eat Fruity Pebbles for breakfast so what do i know.
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > alphabetical list |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|