0

I have the PHP code as below:

 <?php 
                for ($i = 1; $i <= 5; $i++) {
                $checked = ($value['2.Capacity'] == $i) ? ' <img src="img/tick.jpg" width="20px" />' : '';
                echo  '<td>'.$checked.$i.'</td>';
                }

I need:

I want to remove the <img src="img/tick.jpg" width="20px" /> to put CSS style Bold + underlined I do not know how to fix this.

Note:

For the $value['2.Capacity'] it's data from database, it integer value 1 2 3 4 5.

Anyone help me please,Thanks.

3 Answers 3

1
<?php 

            for ($i = 1; $i <= 5; $i++) {
            $checked = ($value['2.Capacity'] == $i) ? ' text-decoration: underline; font-weight: bold;' : '';
            echo  "<td style=$checked>$i</td>";
            }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it works well now but need to add single quote to style=$checked like style='$checked'.
0

Basically you need to understand first the Conditional Statement you're using. You can check out this link for the explanation: http://davidwalsh.name/php-ternary-examples

$checked = ($value['2.Capacity'] == $i) ? ' <img src="img/tick.jpg" width="20px" />' : '';

This code is something like this:

$checked = (conditional statement) ? return true : return false;

The anwer of Akhilraj N S and Barmar will satisfy your needs.

Comments

0
for ($i = 1; $i <= 5; $i++) {
  $style = ($value['2.Capacity'] == $i) ? 'text-decoration: underline; font-weight: bold;" : ''     ;                         
  echo "<td><span style='$style'>$i</span></td>";
}

1 Comment

Fixed my answer to use <span>, not <style>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.