如何使用PHP显示表列?
我试图在php/html中仅当$edit=1时显示两列。以下方面也是如此:如何使用PHP显示表列?,php,html,Php,Html,我试图在php/html中仅当$edit=1时显示两列。以下方面也是如此: <?php if ($edit == 1) { <td align="center"><a href="editor/editor.php?id=<?php echo $row["id"]; ?>" onclick="handleLinkClick(event);">Edit</a></td> <td align
<?php
if ($edit == 1)
{
<td align="center"><a href="editor/editor.php?id=<?php echo $row["id"]; ?>" onclick="handleLinkClick(event);">Edit</a></td>
<td align="center"><a href="removedoc.php?id=<?php echo $row["id"]; ?>" onclick="swalremove(event);">Remove</a></td>
}
?>
但我有一个错误:
Parse error: syntax error, unexpected '< on line 177
分析错误:语法错误,第177行出现意外“<
我如何解决这个问题 更新:
<?php
if ($edit == 1)
{
<td align="center"><a href="editor/editor.php?id=<?php echo $row['id']; ?>" onclick="handleLinkClick(event);">Edit</a></td>
<td align="center"><a href="removedoc.php?id=<?php echo $row['id']; ?>" onclick="swalremove(event);">Remove</a></td>
}
?>
致:
或:
更新:
<?php
if ($edit == 1)
{
<td align="center"><a href="editor/editor.php?id=<?php echo $row['id']; ?>" onclick="handleLinkClick(event);">Edit</a></td>
<td align="center"><a href="removedoc.php?id=<?php echo $row['id']; ?>" onclick="swalremove(event);">Remove</a></td>
}
?>
致:
或:
这样做:
<?php
if ($edit == 1) { ?>
<td align="center"><a href="editor/editor.php?id=<?php echo $row["id"]; ?>" onclick="handleLinkClick(event);">Edit</a></td>
<td align="center"><a href="removedoc.php?id=<?php echo $row["id"]; ?>" onclick="swalremove(event);">Remove</a></td>
<?php } ?>
您需要使用适当的php标记约定。
不要将HTML与PHP混合使用。
在编写原始HTML之前,请始终关闭PHP标记。
您也可以仅在PHP中使用它,如下所示:
<?php
if ($edit == 1) {
echo
'<td align="center"><a href="editor/editor.php?id='.$row["id"].'" onclick="handleLinkClick(event);">Edit</a></td>
<td align="center"><a href="removedoc.php?id='.$row["id"].'" onclick="swalremove(event);">Remove</a></td>';
} ?>
这样做:
<?php
if ($edit == 1) { ?>
<td align="center"><a href="editor/editor.php?id=<?php echo $row["id"]; ?>" onclick="handleLinkClick(event);">Edit</a></td>
<td align="center"><a href="removedoc.php?id=<?php echo $row["id"]; ?>" onclick="swalremove(event);">Remove</a></td>
<?php } ?>
您需要使用适当的php标记约定。
不要将HTML与PHP混合使用。
在编写原始HTML之前,请始终关闭PHP标记。
您也可以仅在PHP中使用它,如下所示:
<?php
if ($edit == 1) {
echo
'<td align="center"><a href="editor/editor.php?id='.$row["id"].'" onclick="handleLinkClick(event);">Edit</a></td>
<td align="center"><a href="removedoc.php?id='.$row["id"].'" onclick="swalremove(event);">Remove</a></td>';
} ?>
您可以定义一个HTML字符串,并向其中添加您可能拥有的任何元素,然后在结尾回显它。这要简单得多:
$html = '';
if ($edit == 1) {
$html .= '<td align="center"><a href="editor/editor.php?id=' . $row["id"] . '" onclick="handleLinkClick(event);">Edit</a></td>';
$html .= '<td align="center"><a href="removedoc.php?id=' . $row["id"] . '" onclick="swalremove(event);">Remove</a></td>';
}
echo $html;
$html='';
如果($edit==1){
$html.='';
$html.='';
}
echo$html;
您可以定义一个HTML字符串,并向其中添加您可能拥有的任何元素,然后在结尾回显它。这要简单得多:
$html = '';
if ($edit == 1) {
$html .= '<td align="center"><a href="editor/editor.php?id=' . $row["id"] . '" onclick="handleLinkClick(event);">Edit</a></td>';
$html .= '<td align="center"><a href="removedoc.php?id=' . $row["id"] . '" onclick="swalremove(event);">Remove</a></td>';
}
echo $html;
$html='';
如果($edit==1){
$html.='';
$html.='';
}
echo$html;
关闭php
在td
开始之前标记,然后在td
之后开始php
标记close@Gulshan:哇。成功了。所以我非常接近……:)关闭php
td之前的标签td
start和php
td之后的标签td
close@Gulshan:哇。成功了。所以我非常接近……:)