0

I have a rating field in the database. If the value of $rating>0, the button should be disabled otherwise button should be enabled.I am saving the HTML code to database to dispaly.

What I have tried is :

 $user_notification->notification ="Delivery date <b>" .$date."</b> and delivery time <b> ".$time." </b> for the truck " .$truck_name. " of mileage ".$mileage_name. " of quantity ".$qty. " has confirmed 
        <br> <a href='#' class='btn btn-primary' >Pay ?</a>
        if(.$rating.'=='.0.'){<a href='/showTransaction/".$buy_id."' class='btn btn-primary' >Review ?</a>}else{<a href='' class='btn btn-primary' disabled >Review ?</a>}";
         $user_notification->save();

The data is saving but What I get in my output as:

Output

How to avoid if and else from showing in html?

CodeHunt
  • 83
  • 1
  • 11

1 Answers1

0

The problem with your code is that you are not closing the string before you add the condition to append to the rest of it. Also, variables do not need to be escaped in strings using double quotes.

$user_notification->notification = "Delivery date <b>$date</b> and delivery time <b>$time</b> for the truck $truck_name of mileage $mileage_name of quantity $qty has confirmed<br><a href='#' class='btn btn-primary'>Pay ?</a>";

if ($rating == 0) {
    $user_notification->notification .= "<a href='/showTransaction/$buy_id' class='btn btn-primary'>Review ?</a>";
} else {
    $user_notification->notification .= "<a href='' class='btn btn-primary' disabled>Review ?</a>";
}

$user_notification->save();
Jacob Mulquin
  • 3,458
  • 1
  • 19
  • 22