Domanda

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...

È stato utile?

Soluzione

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>

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top