0

I am using the following query to check if an entry in the channel images table has any categories marked 'private'.

{exp:query sql="SELECT * FROM exp_channel_images WHERE entry_id = '{entry_id}'
 AND category = 'private' "}
 {if no_results} 0 images {/if}
{/exp:query} 

The {if no_results} output does not work. Can anyone suggest another way I can do this? Thanks

1
  • Are you sure there is a exp_channel_images is an actual table in your database? If you run that query on your database with 'open' do you get any results? – Johnathan Waters May 15 '13 at 21:14
1

Your query seems correct. Although, you can use channel images tag instead:

{exp:channel_images:images entry_id='entry_id' category='private'}
    {if image:no_images} 0 images {/if}
{/exp:channel_images:images}

In case you would like to use query module, it would work also:

{exp:query sql="SELECT COUNT( * ) AS total_images FROM exp_channel_images WHERE entry_id = '{entry_id}' AND category = 'private'"}
 {if total_images == 0} 0 images {/if}
{/exp:query}
1
  • Thanks Bhashkar I had previously tried the channel images tag but it doesn't work. The query module works and I have just simplified it further tojust do a basic count {exp:query sql="SELECT COUNT( * ) AS total_images FROM exp_channel_images WHERE entry_id = '{entry_id}' AND category = 'private'"} {total_images} images {/exp:query} – user579984 May 16 '13 at 8:55
0

I don't have an EE database in front of me, but I could've sworn it was category_id in that table, not category. If your query is invalid, it would prevent no_results from working as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.