Display random view result every x rows I'm trying to display an ad every six rows of a view. I'm thinking of using another view that contains all the ads and displaying a random result of that every 6 rows of the main view.

Drupal 7 &amp; Views 3.14

I have tried to do this but gotten stuck on the displaying something every 6 rows. Here is my code:

...code irrelevant, unedited coded copied from the template file in views module folder...
  &lt;tbody&gt;
    &lt;?php foreach ($rows as $row_count =&gt; $row): ?&gt;
      &lt;tr &lt;?php if ($row_classes[$row_count]) { print 'class="' . implode(' ', $row_classes[$row_count]) .'"';  } ?&gt;&gt;
        &lt;?php foreach ($row as $field =&gt; $content): ?&gt;
          &lt;td &lt;?php if ($field_classes[$field][$row_count]) { print 'class="'. $field_classes[$field][$row_count] . '" '; } ?&gt;&lt;?php print drupal_attributes($field_attributes[$field][$row_count]); ?&gt;&gt;
            &lt;?php print $content; ?&gt;
          &lt;/td&gt;
        &lt;?php endforeach; ?&gt;
      &lt;/tr&gt;
      &lt;?php if ((($row_count % 6) == 0 &amp;&amp; $row_count !== 0): ?&gt;&lt;tr&gt;This is the row after every 6th multiple&lt;/tr&gt;&lt;?php endif; ?&gt;
    &lt;?php endforeach; ?&gt;
  &lt;/tbody&gt;
&lt;/table&gt;


UPDATE: I figured out a way to print a random result. Just add randomize as the only sort in the view. However, I still can't get the printed view result to be in the appropriate location.
Okay, I solved it by using by using an unformatted list instead of a table.

Here is my code in the end:

&lt;?php if (!empty($title)): ?&gt;
  &lt;h3&gt;&lt;?php print $title; ?&gt;&lt;/h3&gt;
&lt;?php endif; ?&gt;
&lt;?php foreach ($rows as $id =&gt; $row): ?&gt;
  &lt;div&lt;?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?&gt;&gt;
    &lt;?php print $row; ?&gt;
  &lt;/div&gt;
&lt;?php 
  $numRows = 6; /* Which row do you want the view to appear? E.g. 6 means that rows 6, 12, 18, etc. will have the view */
  if ((($id - ($numRows - 2) ) % ($numRows - 1)) == 0 &amp;&amp; $id !== 0):
?&gt;
    &lt;div class="ads views-row"&gt;&lt;?php print views_embed_view('VIEW_MACHINE_NAME', 'DISPLAY_ID',''); ?&gt;&lt;/div&gt; 
  &lt;?php endif; ?&gt;
&lt;?php endforeach; ?&gt;