Rocco The Taco Rocco The Taco - 1 month ago 11
PHP Question

PHP isset to change BGColor?

I'm currently using the following code to display text from a variable if it exists to display text:

<th class='techid tooltip' data-tech='".$row."' style=\"background:#CCC\">
<span class='staffinfo ".$techHighLight."'>".$row."- ";
echo
substr($record["EmpLastName"],0,10).(isset($record_StaffSetID) ? "(".$record_StaffSetID.")" : "")."
</span>
</th>


I need to alter the background:#CCC so that if the isset is true it becomes background:#000. I've tried a series of if/else and keep getting syntax errors.

Here is a snippet of what I've tried with no luck:

echo "<th class='techid tooltip' data-tech='".$row."' ".(isset($record_StaffSetID) ? "style=background:#000 !important;" : "style=background:#CCC !important;").">


What is the best way to handle this?

Answer

Try :

<?php
if (isset($record_StaffSetID)) :
?>
<th class='techid tooltip' data-tech="<?php echo $row; ?>" style="background:#CCC">
    <span class='staffinfo <?php echo $row; ?>'>
      <?php echo $row ?> - 
      <?php echo substr($record["EmpLastName"],0,10).(isset($record_StaffSetID) ? "(".$record_StaffSetID.")" : ""); ?>
    </span>
</th>
<?php 
else:
?>
<th class='techid tooltip' data-tech="<?php echo $row ?>" style="background:#000">
    <span class='staffinfo <?php echo $techHighLight ?>'>
      <?php echo $row ?> - 
      <?php echo substr($record["EmpLastName"],0,10).(isset($record_StaffSetID) ? "(".$record_StaffSetID.")" : ""); ?>
    </span>
</th>
<?php endif; ?> 

But it is not really elegant !!