Hey John,

whack is bad right??

Well that all works-ish and is ok-ish - Its not very efficient making
all those calls to the database, you don't need cfoutput inside cfquery
and you may find that you don't get correct results with lots of data.

You can get all the information you need in one query.

<cfquery name="LinksbyCategory" datasource="yourdsn">
SELECT * from globallinks
ORDER BY CategoryValue,LinkDisplayValue
</cfquyer

To output it...

<cfoutput query="LinksbyCategory" group="CategoryValue">
#CategoryValue#
<cfoutput>
&nbsp;&nbsp;#LinkDisplayValue#
</cfoutput>
</cfoutput>

Basically, order your data by the category, then tell cfoutput to group
the output by the category, so that your category is in the outer
loop/cfoutput and your items in that category are in the inner
loop/cfoutput.

Please don't take this the wrong way, but it looks like you could do
with a good beginners guide to SQL and a book on CF to help you.  Have a
search of the archives at www.houseoffusion.com and you'll be able to
find various threads with recommendations for books.

Regards

Stephen

John Munyan wrote:

> I have this table that contains links that are put into 1 of about 10
> categories.  
>
> The table structure is as follows:
>
> Auto-number (Identity Column) | Category Value | HttpLink | DisplayValue
> for Link| UserID | DateTime | Available
>
> The output I was looking for and got is:
>
> Category1
>
>             Link1
>
>             Link2
>
>             Link3
>
> Category2
>
>             Link1
>
>             Link2
>
> CategoryN
>
>             Link1
>
>             Link2  
>
> How I got this is very suspect.  Not really looking to take up anyone's
> time with specific code about how this should be done necessarily but
> wondering how should this be structured?  I don't know if that makes
> sense.  I just can't believe this is write though it is how my mind saw
> it. :-)  I can't see how to otherwise group the links by category unless
> I created one query per each category---which is essentially what I did.
> How whack is this?
>
> Thanks,
>
> John  
>

[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to