我想在PHP表格中显示一个Font Awesome图标。 它应该显示fa-eye图标,如果有一个' ja'在名为' visible'的行中,否则它应显示fa-eye-slash图标。
这是我的代码:
<?php
$statement = $pdo->prepare("SELECT * FROM gamesnw ORDER BY datum");
$result = $statement->execute();
$count = 1;
while($row = $statement->fetch()) {
echo "<tr>";
echo "<td>".$row['tag']."</td>";
echo "<td>".$row['datum']."</td>";
echo "<td>".$row['zeit']."</td>";
echo "<td>".$row['ort']."</td>";
echo "<td>".$row['liga']."</td>";
echo "<td>".$row['heim']."</td>";
echo "<td>".$row['gast']."</td>";
echo "<td>".$row['sr1']."</td>";
echo "<td>".$row['sr2']."</td>";
echo "<td>".$row['reserve']."</td>";
echo "<td>";
print '<a href="gamesettings.php?id='.$row['id'].'" class="btn btn-default btn1">Ändern</a>';
echo "</td>";
echo "<td>";
echo if .$row['visible'] == 'ja'.'<i class="fa fa-eye"></i>' else '<i class="fa fa-eye-slash"></i>';
echo "</td>";
echo "</tr>";
}
?>
我在第三行尝试了它,但它没有工作。 有什么想法吗?
答案 0 :(得分:3)
试试这个:
echo '<i class="fa '.($row['visible'] === 'ja' ? 'fa-eye' : 'fa-eye-slash').'"></i>';
答案 1 :(得分:1)
替换此
echo if .$row['visible'] == 'ja'.'<i class="fa fa-eye"></i>' else '<i class="fa fa-eye-slash"></i>';
^^ Error
到这个
echo ($row['visible'] == 'ja') ? '<i class="fa fa-eye"></i>' : '<i class="fa fa-eye-slash"></i>';