I’m using a custom field to link entries. I wrote a simple sql query to count the related entries.
{exp:query sql="
SELECT cd.entry_id, cd.field_id_1, ct.author_id, ct.title, ct.url_title, ct.view_count_one, ct.year, ct.month, ct.day, m.member_id, m.screen_name
FROM
exp_channel_data cd
INNER JOIN
exp_channel_titles ct
USING(entry_id)
LEFT JOIN exp_members m ON m.member_id = ct.author_id
WHERE field_id_4= '{embed:graankorrel}'
AND entry_id <> '{embed:entry_id}'
ORDER BY 'view_count_one' DESC
"}The query works perfectly. All i want is to show how many related entries have been written. I want to count them.
I thought using the
{total_results}would just give me that; the total results. I used it like this:
{if no_results}0 results{/if}
{if total_results == "1"}
{total_results} result
{if:else}
{total_results} results
{/if}This works really well, until more than one (1) related entries are found. I get double (or triple) results. Like this:
2 results 2 results
Of course this is exactly what the query module should do, but it’s not what i would like to see.
I don’t want EE to loop through the results as this is only generating repeating code. I searched a lot but am not sure if there is a way of removing all results (in the EE part) except the first..
So my question is: Is there a way i can remove all the results (in the looping EE part) except the first?
[Mod Edit: Moved to the CodeShare Corner forum]