duanqiaoren9975 2018-07-27 07:58
浏览 37
已采纳

Php在html中出现

I'm trying to do a simple isset condition in my html with php like this :

 <table cellspacing="0" cellpadding="3" border="0">
        <tr><td><?php print t('Adresse :'); ?> : </td><td><?php print $participant->adresse1; ?></td></tr>
        <tr><td><?php print t(''); ?> : </td><td><?php print $participant->code_postal.' '.$participant->ville; ?></td></tr>
        <tr><td><?php print t(''); ?> : </td><td><?php print $participant->pays; ?></td></tr>
        <?php if(isset($participant->tel_perso)): ?><tr><td><?php print t('Tél :'); ?> : </td><td><?php print $participant->tel_perso; ?></td></tr><?php endif; ?>
        <tr><td><?php print t('Email :'); ?> : </td><td><?php print $participant->email_id; ?></td></tr>
        <tr><td><?php print t('Date de naissance :'); ?> : </td><td><?php print format_date($participant->date_naissance, "custom", "d F Y") ?></td></tr>
 </table>

The problem is that this row is always show, even if the isset return false (I test it in the code before and it works)

WHy it's not working in html ?

  • 写回答

2条回答 默认 最新

  • duanmao1319 2018-07-27 08:47
    关注

    The problem seems to be because your value was set, but it didn't have a value that you wished to show. Without knowing what that value is, perhaps an empty call would be better for you. Displaying only the content when it's NOT ! empty. If that's not working for you, check what the variable is set to with var_dump and comment back here.

    <table cellspacing="0" cellpadding="3" border="0">
        <tr>
            <td><?=t('Adresse :')?></td>
            <td><?=$participant->adresse1?></td>
        </tr>
        <tr>
            <td><?=t('')?> :</td>
            <td><?=$participant->code_postal.' '.$participant->ville?></td>
        </tr>
        <tr>
            <td><?=print t('')?> :</td>
            <td><?=$participant->pays;?></td>
        </tr>
    <?php   if (!empty($participant->tel_perso))):   ?>
        <tr>
            <td><?=t('Tél :')?></td>
            <td><?=$participant->tel_perso;?></td>
        </tr>
    <?php   endif;  ?>
        <tr>
            <td><?=t('Email :')?></td>
            <td><?=$participant->email_id;?></td>
        </tr>
        <tr>
            <td><?=t('Date de naissance :')?></td>
            <td><?=format_date($participant->date_naissance, "custom", "d F Y")?></td>
        </tr>
    </table>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?