Okay, to make it really simple to see the inconsistent behavior, I have created a simple template and snippet that you can play with. Here is the template (called bull):
BULL<br>
Seg 1 = {segment_1}
Seg 2 = {segment_2}
Seg 3 = {segment_3}
Seg 4 = {segment_4}<br><br>
{if segment_3 != "" AND segment_4 == ""}
{exp:query sql="SELECT cat_id FROM exp_categories WHERE cat_url_title = '{segment_3}'"}
{exp:channel:entries channel="products" category="{cat_id}"}
{bull_snip}
{/exp:channel:entries}
{/exp:query}
{if:elseif segment_3 != "" AND segment_4 != ""}
{exp:query sql="SELECT cat_id FROM exp_categories WHERE cat_url_title = '{segment_3}'"}
{exp:channel:entries channel="products" category="{cat_id}" url_title="{segment_4}"}
{bull_snip}
{/exp:channel:entries}
{/exp:query}
{if:else}
{exp:channel:entries channel="products"}
{bull_snip}
{/exp:channel:entries}
{/if}And here is the bull_snip snippet:
-------------------------------------------------------------<br>
{product_photo_1}
{exp:query sql="SELECT file_id FROM exp_files WHERE file_name = '{filename}.{extension}' LIMIT 1"}
{exp:file:entries file_id="{file_id}"}
Filename: {filename}.{extension}
File ID: {file_id}
Image File URL = {file_url}<br>
Image Thumbnail URL = {Product_Thumb_file_url}<br>
{Product_Thumb_file_url}<br>
<!-- {file_url} -->
{/exp:file:entries}
{/exp:query}
{/product_photo_1}
entry_id = {entry_id}<br>
entry_id_path = {entry_id_path}<br><br>
-------------------------------------------------------------<br>If you render it with the basic URL:
http://dev.neuralynx.com/products/bull/
you get 4 different products, each with the proper file_id, and image URLs.
If you render a single product with the URL:
http://dev.neuralynx.com/products/bull/digital_data_acquisition_systems/digital_lynx_16sx
You get a single product with the proper file_id and URLs
The problem arises if you just specify a category, as in the URL:
http://dev.neuralynx.com/products/bull/digital_data_acquisition_systems/
In this case, you get a single file_id repeated for both products in the category! But also, you notice that the {entry_id} and {entry_id_path} is correct for each product, so the template is getting that right. It just seems that the snippet is not parsing or handling the SQL query in the case when a category is specified, but no url_title.
Been banging my head for three days on this problem and am really getting frustrated.