Using a php if statement in the view section

darrenhallinan 06 Jul, 2016
Hi All

I cant seem to get this to work

I want to add a different button to the view section depending on the status of a field value

so heres what i have


<?php
      $itemstatus = "['id']['status']";
      if ($itemstatus = "Sold") {$showedit = "<a href='index.php?option=com_chronoforms5&chronoform=Restock_Traceability_Doc&dataid={id.id}' class='btn btn-primary'>
<i class='fa fa-pencil-square' aria-hidden='true'></i>
Restock This Item
</a>";}
      else {$showedit = "<a href='index.php?option=com_chronoforms5&chronoform=Edit_Traceability_Doc&id={id.id}' class='btn btn-primary'>
<i class='fa fa-pencil-square' aria-hidden='true'></i>
Edit This Document
</a>";}
      echo $showedit;
    ?>



I have also tried replacing
      $itemstatus = "['id']['status']";


With

      $itemstatus = "{id.status}";


The current code above show the restock button even if the item does not have the status of sold

As Always Any help appreciated
GreyHead 06 Jul, 2016
Hi Darren,

Please try $itemstatus = $row['id']['status']; I'm not 100% sure but think that's what you need here.

Bob
darrenhallinan 06 Jul, 2016
Hey Bob

Thanks again for the reply

I tried that alrite i seen it on the forums

But it didnt work, I tried it again just to be sure

So heres what happens

i set the value

<?php
$itemstatus = $row['id']['status'];
?>


when i echo the value, I always get the same value which is sold

But! if i echo the value from the DB using this code:

<?php
 echo $row['id']['status'];
?>

I get the correct value

Im guessing the value sold is been pulled from my if statement somehow

as on a record where the value would be "In Stock" its still getting sold from somewhere, and thats the only place i can see it getting it!


I am just after trying this and it seems to have worked!
if ($itemstatus === "Sold")


I dont understand why that worked . . . but it worked
GreyHead 07 Jul, 2016
Hi darrenhallinan,

I can't tell . . . have you solved this now?

Bob
darrenhallinan 07 Jul, 2016
Sorry Bob yes, its been solved
Working code below

<?php
//Set Item Status
$itemstatus = $row['id']['status'];
?>



<?php
if ($itemstatus === "Sold") {$showedit = "<a href='index.php?option=com_chronoforms5&chronoform=Restock_Traceability_Doc&id={id.id}' class='btn btn-primary'>
<i class='fa fa-pencil-square' aria-hidden='true'></i>
Restock This Item
</a>";}
else {$showedit = "<a href='index.php?option=com_chronoforms5&chronoform=Edit_Traceability_Doc&id={id.id}' class='btn btn-primary'>
<i class='fa fa-pencil-square' aria-hidden='true'></i>
Edit This Document
</a>";}
// Output button
echo $showedit;
//for testing
// echo $itemstatus;
?>
This topic is locked and no more replies can be posted.