<p>I have never tried it on a table field, but you could try:</p>

<pre><code>{% for row in block.example.limit('1').order('RAND()') %}
    {{ row.examplerow }}
{% endfor %} 
</code></pre>

<p><strong>OK, above will not work</strong>. I went back on my theory and actually tried it on a table field I had laying around. This worked for me:</p>

<pre><code>{% set rows = shuffle(block.example) %}

{% for row in rows | slice(0, 1) %}
   {{ row.examplerow }}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-04-25T19:12:22.663Z
If that does work, and returns a single row, you wouldn't need the `for` loop.
Stephen Lewis
CC BY-SA 3.0
2017-04-25T19:43:08.880Z
Thanks for that AbbeyDesign, I tried that and now it returns no records.
Vin
CC BY-SA 3.0
2017-04-25T19:57:01.197Z
What kind of field is it that you are trying to loop through?
AbbeyDesign
CC BY-SA 3.0
2017-04-25T20:28:56.543Z
Trying to loop through a Table field in Matrix.
Vin
CC BY-SA 3.0
2017-04-25T20:53:13.500Z
@Vin I edited the code above. Let me know if that works. I tried it on a table field I had and it worked for me.
AbbeyDesign
CC BY-SA 3.0
2017-04-25T21:32:07.330Z
AbbeyDesign you rock!!! That worked perfect :)
Vin
CC BY-SA 3.0
2017-04-25T19:08:08.903Z
2017-04-26T18:48:22.060Z
2017-04-26T18:48:22.060Z
AbbeyDesign
<p>This is my code I am using, but want to limit it to just one and possibly randomize it also.  Is it possible with Table, I looked at the example on Craft's site but did not see that option.</p>

<pre><code>{% for row in block.example %}
    {{ row.examplerow }}
{% endfor %} 
</code></pre>

CC BY-SA 3.0
2017-04-25T20:12:39.067Z
Have a look at: http://stackoverflow.com/a/38677493/26130
Brad
CC BY-SA 3.0
2017-04-25T20:28:29.827Z
Brad that is something I tried before but it errors as an unknown filter shuffle.  I did take out the shuffle and tried just slice(0,1) and it worked.  Just need the random part now.
Vin
<table-field>
Limit rows using Table
# Limit rows using Table

(Asked by: username_0 on 2017-04-25)

This is my code I am using, but want to limit it to just one and possibly randomize it also.  Is it possible with Table, I looked at the example on Craft's site but did not see that option.
{% for row in block.example %}
    {{ row.examplerow }}
{% endfor %}

**Tags:** table-field

> **Comments:**
> **username_1**: Have a look at: http://stackoverflow.com/a/38677493/26130  
> **username_0**: username_1 that is something I tried before but it errors as an unknown filter shuffle.  I did take out the shuffle and tried just slice(0,1) and it worked.  Just need the random part now.  

---

## 1 answers

### Answer by username_2 on 2017-04-25. Score: 3 | Accepted answer

I have never tried it on a table field, but you could try:
{% for row in block.example.limit('1').order('RAND()') %}
    {{ row.examplerow }}
{% endfor %} 

OK, above will not work. I went back on my theory and actually tried it on a table field I had laying around. This worked for me:
{% set rows = shuffle(block.example) %}

{% for row in rows | slice(0, 1) %}
   {{ row.examplerow }}
{% endfor %}

> **Comments:**
> **username_3**: If that does work, and returns a single row, you wouldn't need the `for` loop.  
> **username_0**: Thanks for that username_2, I tried that and now it returns no records.  
> **username_2**: What kind of field is it that you are trying to loop through?  
> **username_0**: Trying to loop through a Table field in Matrix.  
> **username_2**: @username_0 I edited the code above. Let me know if that works. I tried it on a table field I had and it worked for me.  
> **username_0**: username_2 you rock!!! That worked perfect :)  

---

