-5

Hi I am trying to produce a <td> which also contains an <a> link which will redirect to a function in my controller which also echos the id of my data. Here is my code so far:

<?php 
    if ($this->session->userdata("username")==$info->U_username) {
        echo '<td><a href="<?php echo base_url()gamestalker/edit_content/<?php echo $info->C_id;?>">EDIT</a></td>';
    }
?>

This code produces an error Disallowed Key characters. Any help or comment is highly appreciated.

pavel
  • 26,538
  • 10
  • 45
  • 61

4 Answers4

2

For concatenating strings PHP has . operator.

echo '<td><a href="' . base_url() . 'gamestalker/edit_content/' . $info->C_id . '">EDIT</a></td>';
pavel
  • 26,538
  • 10
  • 45
  • 61
0

You need to add the result of base_url() to the string you want to output, e.g.:

echo '<td><a href="' . base_url() . '/gamestalker/edit_content/' . $info->C_id . '">EDIT</a></td>';
Florian
  • 2,796
  • 1
  • 15
  • 25
0

Either you need to concatinate instead to use php multiple time .use like this

<?php 
    if ($this->session->userdata("username")==$info->U_username){
        echo "<td><a href='".base_url()."'/gamestalker/edit_content/'".$info->C_id."'>EDIT</a></td>";
    }
?>

or don't include html into php tags like this

<?php 
    if ($this->session->userdata("username")==$info->U_username){ ?
       <td><a href="<? echo  base_url() ; ?>/gamestalker/edit_content/<? echo $info->C_id ; ?>">EDIT</a></td>
  <?  }
?>
Manoj Dhiman
  • 5,096
  • 6
  • 29
  • 68
0

You need string concatenation. In PHP you use . for that.

Also codeigniter's base_url can take an argument:

<?php 
    if ($this->session->userdata("username")==$info->U_username){
        echo '<td><a href="'.base_url('gamestalker/edit_content/'.$info->C_id).'">EDIT</a></td>';
    }
?>
Albzi
  • 15,431
  • 6
  • 46
  • 63