0

i have a problem. The problem is Create link to another page or directories with PHP inside HTML Page.

Here is my code

    $query = $this->db->query($sql);                      
     if ($query->num_rows() > 0){
       echo '<a href="<?php echo base_url('admin/edit/'."$g->id_info")?>">Edit</a>';

    } else {                                                       
      echo '<a href="<?php echo base_url('admin/delete/'."$g->id_info")?>" >Delete</a>';
    } 

But the code is returning an error

Parse error: syntax error, unexpected 'admin' (T_STRING), expecting ',' or ';' in D:\xampp\**** on line 150

What is the correct way of embedding a href with PHP inside HTML Page??? Thanks in advance

  • Possible duplicate of [Escaping quotation marks in PHP](https://stackoverflow.com/questions/7999148/escaping-quotation-marks-in-php) – Dave Feb 04 '19 at 01:45

1 Answers1

0

Maybe this way would work for your case:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>

<?php 
    $query = $this->db->query($sql);

    if ($query->num_rows() > 0): ?>

  <a href="<?php echo base_url('admin/edit/'.'$g->id_info')?>">Edit</a>;

<?php else: ?>

  <a href="<?php echo base_url('admin/delete/'.'$g->id_info')?>" >Delete</a>;

<?php endif; ?>

  </body>
</html>
James Garcia
  • 186
  • 6