Help - Search - Members - Calendar
Full Version: cfoutput problem
W3Schools Forum > Server Scripting > ColdFusion
darren
Hello,

i have created a simple cfquery which is

------------------------------------------------
<cfquery name="tmax" datasource="xxxxxx">
SELECT thermaxRange.productName, thermaxRange.productIMG, thermaxLabelRange.range
FROM thermaxRange
LEFT JOIN thermaxLabelRange
ON thermaxRange.thermaxID = thermaxLabelRange.thermaxID
</cfquery>
------------------------------------------------

and basicly what it does is it pulls data from one table, data such as the products name, product image, etc. And then it pulls more data from another table, this data being specific to each product.

when i use the cfoutput tags like this

------------------------------------------
<cfoutput query="tmax">
<p>#productName#</p><br />
<img src="images/thermaxIMG/#productIMG#" title="" alt="" /><br />
<a href="7" >see products</a><br />
#range#
</cfoutput>
------------------------------------------

it repeats the products from one table which is good. But when it comes to displaying the data from another table, it seems to repeat the same product in accordance to the data in the second table.

you can have a look here and see what i mean click me

what you are looking at is the first product being repeated several times . This product should have ABCD next to it only ,not to have it displayed as it is doing so.

example of how it should be displayed

3 level <--- Both of these are pulled from the first table
product image
ABCD <---this is pulled from the second table

and then so on for each of the products.

i dont know why its displaying it like that.

any help would be nice.

cheers
Darren
Skemcin
Try this:
CODE
<cfoutput query="tmax" group="productName">
<b>#productName#</b><br />
<cfoutput>
<img src="images/thermaxIMG/#productIMG#" title="" alt="" /><br />
<a href="7" >see products</a><br />
#range#<br />
<br />
</cfoutput>
<hr><br />
</cfoutput>

I think this is the desired look you are after
darren
Hi Skemcin,

Thanks for replying to my post...

I implemented your code, had to remove the "by" from "group" as it caused some syntax error when i view the page

with your code it now looks like this

is ther a way i could have it displayed like;

3 level
product IMAGE
see products
ABCD

-----------------------------------
4 level
product IMAGE
see products


-----------------------------------
and so on

---------------------------

rather than having it repeated 4 times?

cheers
Darren
Skemcin
ok, try this:
CODE
<cfoutput query="tmax" group="productName">
<b>#productName#</b><br />
<img src="images/thermaxIMG/#productIMG#" title="" alt="" /><br />
<a href="7" >see products</a><br />
<cfoutput>
#range#&nbsp;
</cfoutput>
<br /><hr><br />
</cfoutput>

Because productName and productIMG come from the first (parent) table reference, they would both get put in the first <cfoutput> area. The second table reference (by way of the join) gets put into the second <cfoutput> area.

Did that work?

Oh, sorry about the "group" vs "groupby" syntax error - I had my SQL hat on for a second - interestingly enough their use is not even close to being the same - I catch myself mixing their logic up sometimes.

P.S. So youuuuu guys are the ones behind the new Coors bottle - sweet - and just up the road from me - I work in Elk Grove Village but live in Plainfield. I take it you are in the Glenview office (used to work near there off of Willow Road by the old air force base).
darren
Hi Skemcin,

hahaha , "SQL hat on", i could just imagin it..

Thanks for that, worked perfectly. So really my problem was applying logic to laying out the cfoutput tags correctly.

lol @ coors...yeah we are...in regards to me...I worked 3 months in the glenview office then relocated to england.

Thanks for all your help. smile.gif
Skemcin
Very nice - glad its working.

Yes, it was just a matter of applying the correct logic of your output sequence to match the way your query was structured.

I'm always intrigued to somehow become involved (even in the most distant respect) with an organization that has a somewhat invisible role in something people are very familiar with. It brings to mind those BASF commercials - if you happen to know what I mean there.

Anyway, interesting to learn of you short tenure in Glenview and relocation to England. Seems safe to assume it was worth it - or at least a hard offer to turn down.

Well, have a good evening, I know its a little late there. Let me know if you've got anything else you're working on. I'm sort of the resident ColdFusion guru so feel free to send a PM if you like.

Take care.
darren
Hi Skemcin,

Totally agree with you on that...I was never aware of this company but I knew of their products, subconsiously as most of their products went under the radar for me. Only once they pointed out examples, it was "Woaw, you guys make this...and that?" Its interesting, thats one thing.

Thanks for your positive reply. smile.gif

I think I need more help with my friend logic.

On the product page, I want to give the user the ability to view more data by simply using a javascript function, Show/Hide or toggle is how they are name this script.

Im choosing this because if i opted to show all the data, the pages would be rather large and kinda of ugly.

So what i have done is implemented an existing script for this to happen which you can see here

If you click on the "click for more info", a red box should appear along with all its data. But i think whats happening is because i have laid out that particular data (in my code) like this;

CODE
<cfquery name="tmax" datasource="xxxx">
                SELECT thermaxRange.productName, thermaxRange.productIMG, thermaxLabelRange.range,
                thermaxLabelRange.Celcius, thermaxLabelRange.fahrenheit, thermaxLabelRange.id
                FROM thermaxRange
                LEFT JOIN thermaxLabelRange
                ON thermaxRange.thermaxID = thermaxLabelRange.thermaxID ORDER BY thermaxLabelRange.id ASC
            </cfquery>
            
            <cfoutput query="tmax" group="productName">
                <b>#productName#</b><br />
                <img src="images/thermaxIMG/#productIMG#" title="" alt="" /><br />
                <a href="7" >see products</a><br />
            <cfoutput>    
            </cfoutput>
            <h3 class="spec">Click here for more info</h3>
                <div class="productSpec" style="height:300px;width:300px;background-color:red;">
                    <table class="lables">
                        <tr style="text-align:left;">
                            <td>&nbsp;</td>
                            <td style="font-weight:bold;">&deg;C</td>
                            <td style="font-weight:bold;">&deg;F</td>
                        </tr>
                        <tr>
                            <td><span style="font-weight:bold;">#range#</span></td>
                            <td>#Celcius#</td>
                            <td>#fahrenheit#</td>
                        </tr>
                    </table>
                </div>        
            <br /><hr><br />
            </cfoutput>


The #Celcius# and #fahrenheit# tags only seem to be pulling out the first field of information for every product. I would like it too loop through this table displaying all the data for each product, as It had dont before.

Any ideas to how this could be achieved?

cheers
Dazzclub
Skemcin
ahh, I think its just a matter of moving your <cfoutput> and your </cfoutput> tags around a little.

I think this is close to what you need:
CODE
<cfquery name="tmax" datasource="xxxx">
    SELECT    thermaxRange.productName,
            thermaxRange.productIMG,
            thermaxLabelRange.range,
            thermaxLabelRange.Celcius,
            thermaxLabelRange.fahrenheit,
            thermaxLabelRange.id
    FROM    thermaxRange
            LEFT JOIN thermaxLabelRange ON thermaxRange.thermaxID = thermaxLabelRange.thermaxID
    ORDER BY thermaxLabelRange.id ASC
</cfquery>

<cfoutput query="tmax" group="productName">
<b>#productName#</b><br />
<img src="images/thermaxIMG/#productIMG#" title="" alt="" /><br />
<a href="7" >see products</a><br />
<h3 class="spec">Click here for more info</h3>
<div class="productSpec" style="height:300px;width:300px;background-color:red;">
<table class="lables">
<tr style="text-align:left;"><td>
&nbsp;<br />
</td><td style="font-weight:bold;">
&deg;C<br />
</td><td style="font-weight:bold;">
&deg;F<br />
</td></tr>

<cfoutput>
<tr><td>
<span style="font-weight:bold;">#range#</span>
</td><td>
#Celcius#
</td><td>
#fahrenheit#
</td></tr>
</table>
</cfoutput>
</div>
<br /><hr><br />
</cfoutput>
darren
Hello,

Your right, the code you gave me was close. When I pasted it into my notepad++ and then viewed the page. It worked how I tended it to work, but all that was wrong was that the table itself looked broken. Everything else worked fine.

So I looked at your code and started it from scrath. Building it slowly and testing it.

the final code looked like this;

----------------------------------
<cfoutput query="tmax" group="productName">
<b>#productName#</b><br />
<img src="images/thermaxIMG/#productIMG#" title="" alt="" /><br />
<a href="7" >see products</a><br />
<h3 class="spec">more product info + </h3>
<div class="productSpec" >
<table class="lables" width="200" border="0">
<tr>
<td>&nbsp;</td>
<td style="font-weight:bold;">&deg;C</td>
<td style="font-weight:bold;">&deg;F</td>
<td>&nbsp;</td>
</tr>
<cfoutput>
<tr>
<td style="font-weight:bold;">#range#</td>
<td>#Celcius#</td>
<td>#fahrenheit#</td>
<td>&nbsp;</td>
</tr>
</cfoutput>
</table>
</div>
<br /><hr><br />
</cfoutput>

----------------------------------

You can see it in action here

Im going to mention you in my blog (I only blog as i can never settle on a good design for my portfolio) you have been such a great help.

Cheers mate
Dazzclub
Skemcin
Very nice - I'm glad you were able to use the code and build off of it. I appreciate the kind words and reference. You've got to take a lot of credit too for clearly stating your needs and taking the time to work through it. There are plenty of folk that just want to copy-n-paste solutions - it nice to see you taking the time to not only apply the logic but to really understand it.

Its pretty funny to hear you talk about the inability to settle on a design fro your own site - I can relate. Its like once you decide to do something, you almost always hate it by the time you are done coding it.

In any respect, thanks again for the kind words. I stalk this area of the forums more than the others, so stop by when anything else pops up.

BTW, where do you blog? And on the <a> tag used on the more product info link, you might add onmouseover="this.style.cursor='hand'" so it is more intuitively behaves like a link.
Synook
QUOTE
And on the <a> tag used on the more product info link, you might add onmouseover="this.style.cursor='hand'" so it is more intuitively behaves like a link.

Or just set its CSS cursor attribute to "hand" mellow.gif
darren
Hey guys thanks for the tip. I totally forgot about that, planned to sort it out but got to carried away with the main problem. Cheers again. smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.