2017-01-18 6 views
1

下記のコードを見てください。私はこれを今一時間把握しようとしており、あきらめてここに来ました! コードはエコーの終わりにエコーを出力していますが、それは何の理由もありません.3進演算子の問題に絞っています。問題はどこにあるのか分かりません。すべての種類を試しました... 私は3者間違った形式を持っていますか?エコーには、エコーのスパンをエコーする3値演算子があります

コードが値をチェックします。値が存在する場合、最初のセルに目盛りグリフが表示され、変数の値が2番目のセルにエコーされます。

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>"; 

答えて

1

非常に近いですが、見るべきことはいくつかあります。

  • 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>";