Question

Here's the code I'm using for my table:

<tbody>
      {foreach key=num item=referral from=$referrals}
      {if $referral.commission neq "$0.00 USD"}
      <tr>
        <td>{$referral.date}</td>
        <td>{$referral.service}</td>
        <td>{$referral.amountdesc}</td>
        <td>{$referral.commission}</td>
        <td>{$referral.status}</td>
      </tr>
      {/if}
      {foreachelse}
        <tr>
           <td colspan="6">{$LANG.norecordsfound}</td>
        </tr>
      {/foreach}
</tbody>

Basically if $referral.commission is $0.00 USD then I don't want that row to show. However, right now those rows are showing and I'm not sure what I'm doing wrong...

Was it helpful?

Solution

It's your quotes. Use single quotes and change the if statement to '$0.00 USD' instead of using double quotes.

<tbody>
      {foreach key=num item=referral from=$referrals}
      {if $referral.commission != '$0.00 USD'}
      <tr>
        <td>{$referral.date}</td>
        <td>{$referral.service}</td>
        <td>{$referral.amountdesc}</td>
        <td>{$referral.commission}</td>
        <td>{$referral.status}</td>
      </tr>
      {/if}
      {foreachelse}
        <tr>
           <td colspan="6">{$LANG.norecordsfound}</td>
        </tr>
      {/foreach}
</tbody>

OTHER TIPS

try this:

<tbody>
{foreach key=num item=referral from=$referrals}
{if $referral.commission neq "$0.00 USD"}
<tr>
  <td>{$referral.date}</td>
  <td>{$referral.service}</td>
  <td>{$referral.amountdesc}</td>
  <td>{$referral.commission}</td>
  <td>{$referral.status}</td>
</tr>
{else}
    <tr>
        <td colspan="6">{$LANG.norecordsfound}</td>
    </tr>
{/if}
{/foreach}
</tbody>

For more details to use if/else inside foreach loop refer http://www.smarty.net/docs/en/language.function.foreach.tpl

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top