Skip to content
Advertisement

How to display a table column using PHP?

I am trying to show two columns only if $edit = 1 in php/html. So did the following:

<?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>
         }
?>

But I get an error:

Parse error: syntax error, unexpected '< on line 177

How do I solve this problem?

Advertisement

Answer

Update:

<?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>
      }
?>

To:

<?php
   if ($edit == 1)
   {
    echo '<td align="center"><a href="editor/editor.php?id='.$row['id'].'" onclick="handleLinkClick(event);">Edit</a></td>';
    echo '<td align="center"><a href="removedoc.php?id='.$row["id"].'" onclick="swalremove(event);">Remove</a></td>';
 }
?>

OR:

<?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 } ?>
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement