<p>Let me show you the quickest solution I could think of. 
If you put it in <code>{% cache %}</code> tags, you should be fine. You could also create a little plugin that returns the required data from one big-ass query, if you're into building plugins. If you have <em>any</em> plugin experience, then building a plugin is what I would do.</p>

<pre><code>{% set distributors = craft.entries.section('distributors').limit(null) %}
{% set allRelatedProducts = craft.entries.section('products').relatedTo(distributors).limit(null) %}

&lt;table&gt;
    &lt;thead&gt;
        &lt;tr&gt;
            &lt;th&gt;Distributor&lt;/th&gt;
            {% for product in allRelatedProducts %}
                &lt;th&gt;{{ product.title }}&lt;/th&gt;
            {% endfor %}
        &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
        {% for distributor in distributors %}
            {# Get ids for all products related to distributor #}
            {% set productsForDistributor = craft.entries.section('products').relatedTo(distributor).limit(null).ids() %}
            &lt;tr&gt;
                &lt;td&gt;{{ distributor.title }}&lt;/td&gt;
                {% for product in allRelatedProducts %}
                    {# 
                     # Check if product ID is in array containing this distributor's products
                     # and display value accordingly
                     #}
                    &lt;td&gt;{{ product.id in productsForDistributor ? 'yes' : 'no' }}&lt;/td&gt;
                {% endfor %}
            &lt;/tr&gt;
       {% endfor %}
    &lt;/tbody&gt;
&lt;/table&gt;
</code></pre>

CC BY-SA 3.0
2015-06-29T21:18:21.233Z
2015-06-29T21:23:35.217Z
2015-06-29T21:23:35.217Z
Paul
<p>I'm building a site that contains a listing of products and distributors. I have a channel for each, and each entry in the distributors channel contains a relationship field to tie it to any number of entries in the products channel. There are about 20 entries in each channel.</p>

<p>I need to set up a page with a table that includes all of the products across the top, and all of the distributors in the left column, with a check box in each cell where there is a relationship between the two.</p>

<p>I know how to just use standard related entries tags to output the distributors and list out the related products for each, but is there a way get it into the table format, without a ridiculous number of queries?</p>

<entries><relations>
Display all related entries in a table
# Display all related entries in a table

(Asked by: username_0 on 2015-06-29)

I'm building a site that contains a listing of products and distributors. I have a channel for each, and each entry in the distributors channel contains a relationship field to tie it to any number of entries in the products channel. There are about 20 entries in each channel.

I need to set up a page with a table that includes all of the products across the top, and all of the distributors in the left column, with a check box in each cell where there is a relationship between the two.

I know how to just use standard related entries tags to output the distributors and list out the related products for each, but is there a way get it into the table format, without a ridiculous number of queries?

**Tags:** entries, relations

---

## 1 answers

### Answer by username_1 on 2015-06-29. Score: 2 | Accepted answer

Let me show you the quickest solution I could think of. 
If you put it in {% cache %} tags, you should be fine. You could also create a little plugin that returns the required data from one big-ass query, if you're into building plugins. If you have any plugin experience, then building a plugin is what I would do.
{% set distributors = craft.entries.section('distributors').limit(null) %}
{% set allRelatedProducts = craft.entries.section('products').relatedTo(distributors).limit(null) %}


    
        
            Distributor
            {% for product in allRelatedProducts %}
                {{ product.title }}
            {% endfor %}
        
    
    
        {% for distributor in distributors %}
            {# Get ids for all products related to distributor #}
            {% set productsForDistributor = craft.entries.section('products').relatedTo(distributor).limit(null).ids() %}
            
                {{ distributor.title }}
                {% for product in allRelatedProducts %}
                    {# 
                     # Check if product ID is in array containing this distributor's products
                     # and display value accordingly
                     #}
                    {{ product.id in productsForDistributor ? 'yes' : 'no' }}
                {% endfor %}
            
       {% endfor %}


---

