如何让一段html代码经过php程序的if语句判断后显示

问题的提出:如何让一段html代码经过php程序的if语句判断后显示。这两天修改 http://JustCool.in 上的一个主题,碰到如题所说的一个问题,经过查阅资料搞定了,写个帖子以后备查,免得又去到处找。

代码构想如下:

<?php
for($i=0;$i<$client_num_rows;$i++)
    {
    $client_num = mysql_fetch_array($clientresult, MYSQL_ASSOC);
    //echo $client_num_rows;

    ?>
    <div id="Layer1">
        <div id="Layer12">
     ////如果i=0,执行下面的html.
    <a href="http://127.0.0.1/client31.php?clientaddr=<?php echo $client_num['ip']?>&dtime=
    <?php echo $endtime?>&stime=<?php echo $starttime?> " target="_blank">
    <img src="./Image/people1.jpg" width="78" height="53" alt="CPE1CLIENT1" style=
    "position:absolute; left:<?php echo $i*50?>px; width:51px; height:57px;" border=0 /></a>
    /////如果i=1,只想下面的html.
    <a href="http://127.0.0.1/client41.php?clientaddr=<?php echo $client_num1['si'] ?>&dtime=
    <?php echo $date2?>&stime=<?php echo $realtime1?> " target="_blank">
    <img src="./Image/people2.jpg" width="78" height="53" alt="CPE1CLIENT1" style=
    "position:absolute; left:<?php echo $i*50?>px; width:51px; height:57px;" border=0 /></a>
        </div>
</div>
        <?php
    }
?>
基本语法:
<?php
if(0)
{
?>
<div>aaaaaaa</div>
<?php
}
else
{
?>
<div>bbbbb</div>
<?php
}
?>
修改后代码:
<?php
for($i=0;$i<$client_num_rows;$i++)
  {
  $client_num = mysql_fetch_array($clientresult, MYSQL_ASSOC);
  //echo $client_num_rows;

  ?>
  <div id="Layer1">
  <div id="Layer12">
<?php
  if($i==0){
////如果i=0,执行下面的html.
?>
  <a href="http://127.0.0.1/client31.php?clientaddr=<?php echo $client_num['ip']?>&dtime=
  <?php echo $endtime?>&stime=<?php echo $starttime?> " target="_blank">
  <img src="./Image/people1.jpg" width="78" height="53" alt="CPE1CLIENT1" style=
  "position:absolute; left:<?php echo $i*50?>px; width:51px; height:57px;" border=0 /></a>
<?php
}
  else{ //如果i=1,只想下面的html.
?>
  <a href="http://127.0.0.1/client41.php?clientaddr=<?php echo $client_num1['si'] ?>&dtime=
  <?php echo $date2?>&stime=<?php echo $realtime1?> " target="_blank">
  <img src="./Image/people2.jpg" width="78" height="53" alt="CPE1CLIENT1" style=
  "position:absolute; left:<?php echo $i*50?>px; width:51px; height:57px;" border=0 /></a>
<?php
}
?>
  </div>
</div>
  <?php
  }
?>
基本语法,留着参考!!!


标签:  |  |  | 
将此文分享到:


转载请注明来自风腾网-wordpress企业主题,本文地址:http://fengten.com/755.html
除非注明,风腾网-wordpress企业主题文章均为原创,转载请注明出处和链接!
友荐云推荐

相关文章

4 条评论

*

*

顶部 友荐云推荐