Basic php help

So I want to hide or display a html button based on a mysql data value. The button has a link to a specific page to update a record, I can do both but can't combine the code :confused:

Show/hide button:

<?php
if($row_spec_rx['locked'] == 1) {
echo "locked";
}
else {
echo "button goes here";
 }
?>

Buttons and link:

<a href="update_spec_rx.php?spec_RxID=<?php echo  $row_spec_rx['spec_rx_id']; ?>"  target="_parent"><button>Amend</button></a>

Basically I need to include the button code where echo "button goes here" is.

Thanks for any help :slight_smile:

Oh, I see what you mean.

You are trying to include PHP tags inside PHP tags, which isn't going to work.

Remember that PHP { } and <?php ... ?> are independent of each other though! This is valid:

<?php

for($n=0; $n < 10; $n++)
{

?>
<h3>Hello World!</h3>
<?php

}

?>

The for-loop crosses straight over outside-PHP contents ten times, effectively "printing" them ten times just because the code passed it. I don't know any other language that can do this.

You can even mix them. So you can do:

<?php if($variable) { ?>
<h3>HTML Contents <?php echo $var ?> </h3>
<?php } else { ?>
<h3>Other HTML Contents <?php echo $othervar ?></h3>
<?php } ?>

If I simply do a cut & paste:

<?php if($row_spec_rx['locked'] == 1)  { 
echo "locked"; 
} 
else { 
<a href="update_spec_rx.php?spec_RxID=<?php echo  $row_spec_rx['spec_rx_id']; ?>"  target="_parent"><button>Amend</button></a>;  
} 
?>

I get:

We crossposted. Read my post above :slight_smile:

Thanks for the reply but my php is too basic for it to help :frowning:

Edit:
Actually I managed it, Thanks
the final code

<?php echo $row_spec_rx['spec_rx_id']; ?></td>
    <td>
    <p><?php
    if($row_spec_rx['locked'] == 1) {
    echo "Locked";
    }
    else { ?>
<a href="update_spec_rx.php?spec_RxID=<?php echo $row_spec_rx['spec_rx_id']; ?>"><button>Amend</button></a>
<?php    }
    ?>
1 Like

Yes! Exactly what I meant. You got the idea.