具有三元运算符的回声具有回声的跨度



请参阅下面的代码,我已经尝试了一个小时,但已经放弃并来到这里!代码在回声的末尾输出错误,它没有给出任何原因,我已经将其缩小到三元运算符的问题,这是我第一次使用一个,所以我不确定问题在哪里,并尝试了各种...我弄错了三元的格式吗?

代码检查一个值,如果该值存在,它将用刻度字形填充第一个单元格,变量的值将回显到第二个单元格中。

echo "<table id='tbl' class='defecttable'>
    <tr>
        <th>Trailer:</th>
      <td>*Trailer*</td>  
        <th>Vehicle Mileage:</th>
        <td>*vehicle mileage*</td>        
    </tr>
    <tr>
        <th>Checks To Be Made</th>
        <th>Checked</th>
        <th>Reportable Defect?</th>
        <th>Defect Description</th>
    </tr>
    <tr>
        <th>Fuel/Oil Leaks:</th>
        <td><span class='glyphicon glyphicon-ok-circle'></span></td>  
        <td>".((isset($defect[fuel]) ? '<span class=glyphicon glyphicon-ok-circle"></span>': '')."</td>
        <td>".((isset($defect[fuel]) ? $defect[fuel]: '')."</td>       
    </tr>";

非常接近,但有几件事要看。

  • 在您的每个isset之前都有一个额外的(
  • 你的意思是使用$defect['fuel']而不仅仅是$defect[fuel]吗?如果您没有用单引号或双引号将燃料括起来,则假定它是一个常数。

结果:

echo "<table id='tbl' class='defecttable'>
    <tr>
        <th>Trailer:</th>
      <td>*Trailer*</td>  
        <th>Vehicle Mileage:</th>
        <td>*vehicle mileage*</td>        
    </tr>
    <tr>
        <th>Checks To Be Made</th>
        <th>Checked</th>
        <th>Reportable Defect?</th>
        <th>Defect Description</th>
    </tr>
    <tr>
        <th>Fuel/Oil Leaks:</th>
        <td><span class='glyphicon glyphicon-ok-circle'></span></td>  
        <td>".(isset($defect['fuel']) ? '<span class=glyphicon glyphicon-ok-circle"></span>': '')."</td>
        <td>".(isset($defect['fuel']) ? $defect['fuel']: '')."</td>       
    </tr>";

最新更新