我希望链接仅在$data['block']
等于1,3或4时显示。如果它等于2或5,则不显示。
<td style="font-size:18px;color:#f0cb01;">
<a href="kickcodes.php?id='.$data["block"].'">Reason Codes</a>
</td>
修改
while ($data = mysql_fetch_array($query)) {
echo '
<tr style="background-color:#576c11;">
<td style="font-size:18px; color:#f0cb01;">'.$data["keyword"].'</td>
<td style="font-size:18px;color:#f0cb01;">'.$data["block"].'</td>
<td style="font-size:18px;color:#f0cb01;">'.$data["phone"].'</td>
<td style="font-size:18px;color:#f0cb01;">'.$data["Reason"].'</td>
<td style="font-size:18px;color:#f0cb01;"><a href="kickcodes.php?id='.$data ["block"].'">Kickcodes</a></td>'
echo '<td style="font-size:18px;color:#f0cb01;">';
if( $data['block'] == 1 || $data['block'] == 3 || $data['block'] == 4)
{
echo '<a href="kickcodes.php?id='.$data["block"].'">Reason Codes</a>';
} else
{
echo '<span>Reason Codes</span>'; // Or echo nothing
}
echo '</td>';
答案 0 :(得分:3)
这将有效:
<td style="font-size:18px;color:#f0cb01;">
<?php if (in_array($data["block"], array(1,3,4)){?>
<a href="kickcodes.php?id='.$data["block"].'">Reason Codes</a>
<?php}?>
</td>
答案 1 :(得分:1)
echo '<td style="font-size:18px;color:#f0cb01;">';
if ($data['block'] == 1 || $data['block'] == 3 || $data['block'] == 4) {
echo '<a href="kickcodes.php?id='.$data["block"].'">Reason Codes</a>';
}
echo '</td>';
如果你使用的是单词而不是数字,你可以这样做:
echo '<td style="font-size:18px;color:#f0cb01;">';
if ($data['block'] == 'block 1' || $data['block'] == 'block 3' || $data['block'] == 'block 4') {
echo '<a href="kickcodes.php?id='.$data["block"].'">Reason Codes</a>';
}
echo '</td>';
希望这会有所帮助:)
答案 2 :(得分:1)
只需将您想要链接的条件放在if
语句中:
echo '<td style="font-size:18px;color:#f0cb01;">';
if( $data['block'] == 1 || $data['block'] == 3 || $data['block'] == 4)
{
echo '<a href="kickcodes.php?id='.$data["block"].'">Reason Codes</a>';
} else
{
echo '<span>Reason Codes</span>'; // Or echo nothing
}
echo '</td>';
在表格中省略<td>
标记是没有意义的,这就是为什么我把它放在if
语句之外。
while ($data = mysql_fetch_array($query)) {
echo '
<tr style="background-color:#576c11;">
<td style="font-size:18px; color:#f0cb01;">'.$data["keyword"].'</td>
<td style="font-size:18px;color:#f0cb01;">'.$data["block"].'</td>
<td style="font-size:18px;color:#f0cb01;">'.$data["phone"].'</td>
<td style="font-size:18px;color:#f0cb01;">'.$data["Reason"].'</td>
<td style="font-size:18px;color:#f0cb01;"><a href="kickcodes.php?id='.$data ["block"].'">Kickcodes</a></td>';
echo '<td style="font-size:18px;color:#f0cb01;">';
if( $data['block'] == 1 || $data['block'] == 3 || $data['block'] == 4)
{
echo '<a href="kickcodes.php?id='.$data["block"].'">Reason Codes</a>';
}
else
{
echo '<span>Reason Codes</span>'; // Or echo nothing
}
echo '</td>';