1
votes

I hope I'm missing something really obvious here, because for the life of me I can't figure this one out at all!

I have a cfquery with some joins as follows;

SELECT f.*, p.ID AS prID, p.product_name, p.shortname, i.newthumb, 
(SELECT AVG(reviewrating) FROM product_reviews AS pr WHERE pr.productid=p.id) AS reviewrating, 
(SELECT description FROM product_descriptions AS d WHERE d.productid=p.id LIMIT 1) AS description
FROM followers_p f
LEFT JOIN products p
ON f.productID=p.ID
LEFT JOIN product_images i
ON i.productid=p.ID
WHERE f.wUserID='#getuser.wUserID#'
ORDER BY f.cID DESC

That executes fine and a cfdump of the query shows data is returned as it should be.

Further down the page, I'm running the cfoutput query. However, it's giving me an error 'Variable NEWTHUMB is undefined. '

I've tried grabbing the image as a subquery with Limit 1 and a few other things, but the result is always the same - cfdump shows the correct data, cfoutput gives an undefined error.

Anything else I can try to figure this one out? I've noticed a similar issue occurring on another page too.

Edit - the cfoutput code;

<cfoutput query="getproductfollow">

    <a href="/#ID#/#shortname#"><img alt="#product_name#" src="#newthumb#"></a>
    <a href="/#ID#/#shortname#">#product_name#</a></span>

</cfoutput>
1
Please post your cfoutput code - James Hill
Yes, show us this: "Further down the page, I'm running the cfoutput query." - Evik James
Apologies - I have add the cfoutput code to the original post. - Lee
if you scope your variables does that change anything? instead of you src="#newthumb#" does src="#getproductfollow.newthumb#" work? - Matt Busche

1 Answers

1
votes

The name of your query isn't in your code, so I can't guarantee this is correct. It seems to be that your error is in your reference to your newthumb variable.

Your query should look like this:

<cfquery name="getproductfollow">
    // SQL GOES HERE
</cfquery>

Your output should look like this:

<cfoutput query="getproductfollow">
    <a href="/#ID#/#shortname#"><img alt="#product_name#" src="#newthumb#"></a>
    <a href="/#ID#/#shortname#">#product_name#</a></span>
</cfoutput>

You should show your ENTIRE query, wrapped in the as well as your . That would be really helpful.