-2

I want hide my one button and so I am looking for add style = "display:none;" in it but since I am already using PHP code for echo that button, I am confused how I can use it. I am trying to do it like below

 <?php
 $style = "";

 if($this->session->userdata('user_id') == $member['user_id']) {                         
     $style = "style='display:none;'";                   
 }

 if ($member2 == 0){                               
     echo '<a href="'.site_url('members/addfriend/'.$member['user_id']).'" class="btn btn-primary">Add As Friend <?php echo $style;?> </a>';
 } else {
     echo '<a href="'.site_url('members/removefriend/'.$member['user_id']).'" class="btn btn-primary">Remove Friend </a>';
 }
 ?>

I am looking for apply above style code in my Add Friend button but I am not getting idea how I can use $style variable in my below line code

echo '<a href="'.site_url('members/addfriend/'.$member['user_id']).'" class="btn btn-primary">Add As Friend <?php echo $style;?> </a>';

Let me know if someone can help me for do it. Thanks!

treyBake
  • 6,440
  • 6
  • 26
  • 57
rajrathod
  • 89
  • 8

1 Answers1

3

That's probably just a syntax error. Try it like this:

<?php

$style = "";
if ($this->session->userdata('user_id') == $member['user_id']) {
    $style = "style='display:none;'";
}

if ($member2 == 0) {
    echo '<a href="'.site_url('members/addfriend/'.$member['user_id']);.'" class="btn btn-primary">Add As Friend "'.$style.'"> </a>'; 
   //Here's the change!
} else {
    echo '<a href="' . site_url('members/removefriend/' . $member['user_id']) . '" class="btn btn-primary">Remove Friend </a>';
}


?>

You had a php opening tag inside php, that won't ever work.

Tilo
  • 46
  • 6