ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Getting the count from an exp:query inside of exp:weblog:entries

March 17, 2010 4:58pm

Subscribe [1]
  • #1 / Mar 17, 2010 4:58pm

    Aaron Gustafson

    20 posts

    After playing around a bit, I came up with the following solution:

    {exp:weblog:entries weblog="services"
                        disable="categories|category_fields|member_data|pagination|trackbacks"}
      {exp:query sql="SELECT @row := 0"}{/exp:query}
      {exp:query sql="SELECT @row := @row + 1 AS `query_count`
                             `project`.`title` AS `project_name`
                      FROM   `exp_weblog_titles` AS `project`
                        INNER JOIN `exp_relationships` AS `service_projects` ON `project`.`entry_id` = `service_projects`.`rel_parent_id`
                      WHERE `project`.`weblog_id` = 13
                        AND `service_projects`.`rel_child_id` = {entry_id}
                      LIMIT 10"}
        {if query_count=="1"}
    <ul>
        {/if}
        {if query_count!="10"}
      <li>{project_name}</li>
        {/if}
        {if query_count=="9"}
      <li>…and many more</li>
    </ul>
        {/if}
      {/exp:query}
    {/exp:weblog:entries}

    Note: it doesn’t work with ORDER BY clauses, but it does work nicely for other things. For more, see my blog post on the topic.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases