ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old March 19th, 2008, 09:29 PM
curiousnewbie's Avatar
curiousnewbie curiousnewbie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 56 curiousnewbie User rank is Private First Class (20 - 50 Reputation Level)curiousnewbie User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 23 h 52 m 4 sec
Reputation Power: 2
Nested loop ???

Ok, excuse bad english

Ok what iam trying to do is this;

i have a query to retrieve all products from catalogue (single table)

Then i also want to query another table for info based on ID of parent record (displayed in list).

<START Loop a for products pulled from TABLE A>
<product name>
<product image>
---<loop for detials based on id of parent loop and pulled from TABLE B>
----<detail 1>
----<detail 1>
----<detail 1>
---</loop for detials>
</Loop a for products>


Now i know how loops work, and have a grasp on mysql ect.

but i never use nested loop before, can someone point me in the direction of help/examples or a snip of code from somewhere showing me how this is done.

many thanks

Last edited by curiousnewbie : March 19th, 2008 at 09:41 PM.

Reply With Quote
  #2  
Old March 19th, 2008, 10:16 PM
curiousnewbie's Avatar
curiousnewbie curiousnewbie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 56 curiousnewbie User rank is Private First Class (20 - 50 Reputation Level)curiousnewbie User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 23 h 52 m 4 sec
Reputation Power: 2
pull from an array of structures maybe ?? *shrugs*

Reply With Quote
  #3  
Old March 20th, 2008, 12:05 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,475 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 17 h 7 m 51 sec
Reputation Power: 42
No. Stop. Learn SQL (the query language). Whenever you start thinking that you need to do a query and then loop over it to run more queries, that almost absolutely means that you need an inner join. In other words, once you understand joins, you can do this in one query instead of having to loop and run many separate queries.
__________________
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

Reply With Quote
  #4  
Old March 20th, 2008, 03:16 AM
curiousnewbie's Avatar
curiousnewbie curiousnewbie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 56 curiousnewbie User rank is Private First Class (20 - 50 Reputation Level)curiousnewbie User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 23 h 52 m 4 sec
Reputation Power: 2
lol ironically a join is what i try atm

Reply With Quote
  #5  
Old March 20th, 2008, 06:52 AM
curiousnewbie's Avatar
curiousnewbie curiousnewbie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 56 curiousnewbie User rank is Private First Class (20 - 50 Reputation Level)curiousnewbie User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 23 h 52 m 4 sec
Reputation Power: 2
Ok, i dont come much here for help, but i am in real need

I made 2 tables in MySql 5 database just to figure this out, this is my sql code;

Code:
SELECT
    product.pName
    , product.pImg
    , detail.detail
FROM
    Intouch.detail
    INNER JOIN Intouch.product 
        ON (detail.pId = product.pId);


This gets all data i need, like so;

http://img186.imageshack.us/img186/6776/showub9.jpg

But i need product name to be distinct (yes i know distinct clause to use with SELECT) but i can not get it to work.

Or i need to use CF to display the products distinctly.

i not ask for much help here, but i try to help others, please does someone know how to make this work ??


This is why i do not approach this problem in first place like this (with join) or with single querey (KITELESS)

i think i need to make nested loops with coldfusion, cause i cant see way of making this work using JOIN alone. i maybe need coldfusion to go through product distinctly and make array, then loop through descriptions, and place them in structure within array using pId as relationship. ???

Last edited by curiousnewbie : March 20th, 2008 at 07:05 AM.

Reply With Quote
  #6  
Old March 20th, 2008, 07:39 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,475 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 17 h 7 m 51 sec
Reputation Power: 42
Yes, since I assume the combination of productName, productImage, and detail are all unique, you can't use DISTINCT here. Just to be clear, if the name, image, and detail are the same for each product, you should be able to to do this with DISTINCT.

Anyway, to deal with the first situation, what you can do is order the result set, and then use <cfoutput group=""> like this:

Code:
<cfquery name="myQuery" datasource="myDSN">
SELECT
    product.pName
    , product.pImg
    , detail.detail
FROM
    Intouch.detail
    INNER JOIN Intouch.product 
        ON (detail.pId = product.pId)
ORDER BY
    product.pName
</cfquery>

<cfoutput query="myQuery" group="pName">
	#pName# 
	(This will show only once for all rows that have the same product name).
	<cfoutput>
	#pImg# - #detail#
	(This will show for each row.)
	</cfoutput>
</cfoutput>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Nested loop ???


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway