Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP显示表列?_Php_Html - Fatal编程技术网

如何使用PHP显示表列?

如何使用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/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="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:哇。成功了。所以我非常接近……:)