title: How to use PHP variables in my ExpressionEngine template for counting?
body: <p>Hokay, so. Here's my embedded template, chilling:</p>
  
  <pre><code>&lt;? $i=0; ?&gt;
  
  {exp:channel:entries 
      channel="products" 
      dynamic="no" 
      entry_id="{embed:ids}"
  }
  
      &lt;? $i++; ?&gt;
  
      {exp:playa:parents 
          field_id="25" 
          limit="1"
      }
  
          &lt;!-- product --&gt;
  
          {if no_parents}
              &lt;? $i--; ?&gt;
          {/if}
  
      {/exp:playa:parents}
  
      {if no_results}
          No results!
      {/if}
  
  {/exp:channel:entries}
  
  &lt;? if ($i === 0 ) { echo 'No products found!'; } ?&gt;
  </code></pre>
  
  <p>The logic I had for this <code>$i</code> variable was to get an accurate reading of whether any results have been output. "Result" in this sense refers to what gets output by Playa.</p>
  
  <p>The <code>exp_channel_entries</code>'s <code>no_results</code> test only gets triggered if <code>{embed:ids}</code> is empty or the embedded ids don't correspond to entries in the channel.  If the <code>entries</code> method returns entries but none of the results have a parent entry, nothing gets output -- and I needed a way to determine this, and I thought "Hmm, PHP should be able to do this, right?"</p>
  
  <p>The desired outcome is that <code>'No products found!'</code> gets output when <code>$i = 0</code> but for some reason, <code>$i</code> is always <code>0</code> regardless of what entries get spit out.</p>
  
  <p>Oh, and before you ask: YES, PHP is indeed enabled. Example: Below, <code>{embed:ids} = 41|78|79|80|81|87|106</code>. When set to OUTPUT, the PHP tags just get printed in the source:</p>
  
  <pre><code>&lt;? $i=0; ?&gt;
  &lt;? $i++; ?&gt;
  &lt;!-- product --&gt;
  &lt;? $i++; ?&gt;
  &lt;!-- product --&gt;
  &lt;? $i++; ?&gt;
  &lt;!-- product --&gt;
  &lt;? $i++; ?&gt;
  &lt;!-- product --&gt;
  &lt;? $i++; ?&gt;
  &lt;? $i--; ?&gt;
  &lt;? $i++; ?&gt;
  &lt;!-- product --&gt;
  &lt;? if ($i === 0 ) { echo 'No products found!'; } ?&gt;
  </code></pre>
  
  <p>If I switch PHP parsing to INPUT the tags get processed, but <code>$i = 0</code> every time.</p>
  
  <p>I added an <code>echo $i;</code> after <code>$i=0</code>, <code>$i++</code>, and <code>$i--</code>. With PHP set to OUTPUT, as before, the statements just get output in the page source.  With PHP set to INPUT, I get this string of values: <code>0 1  1  1  1  1 01</code></p>
  
  <p>So my questions to you, StackOverflow community, is:<br>
  1) Why does PHP in OUTPUT mode just output the PHP tags without processing them?<br>
  2) How can I keep count of the number of product parents being output?</p>