1

I am getting goof up, can someup help like

v_central_locking value can either be 0 or 1

Below is the code to display value - fetched from database

       <?php
           <!--box start-->
            <div class="common-box">
                <div class="common-box-left">Central Lock</div>
                <div class="common-box-right">
                <input name="Central Lock" type="text" class="text-box" value="'.$rows->v_central_locking .'" readonly=""/>               
                </div>
            </div>
            <!--box end-->
       ?>

How to have it with If clause in div where if value is zero - it will display message Like

      if (v_central_locking==0)
      { 
       echo 'Doesnt Have';
      }
       else
      { 
       echo 'Yes a Feature';
      }

can someone help pls

Modified

   <?php
 <!--box start-->
            <div class="common-box">
                <div class="common-box-left">Central Lock</div>
                <div class="common-box-right">
                    <input name="Central Lock" type="text" class="text-box" value="'. ($rows->v_central_locking == 0) ? 'Yes' : 'Yep' .'" readonly=""/>
                </div>
            </div>
            <!--box end-->
     ?>

1 Answer 1

2

Try something like

<!--box start-->
<div class="common-box">
    <div class="common-box-left">Central Lock</div>
    <div class="common-box-right">
    <input name="Central Lock" type="text" class="text-box" value="<?php echo ($rows->v_central_locking == 0) ? 'Nope' : 'Yep'; ?>" readonly=""/>               
    </div>
</div>
<!--box end-->

For reference: http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary

After your edit

You cannot simply put HTML code within PHP tags like that. You should add an echo and adjust your code like the following:

<?php
    echo '
    <!--box start-->
    <div class="common-box">
        <div class="common-box-left">Central Lock</div>
        <div class="common-box-right">
            <input name="Central Lock" type="text" class="text-box" value="' . ($rows->v_central_locking == 0? 'Nope' : 'Yep') . '" readonly=""/>
        </div>
    </div>
    <!--box end-->';
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, edited my query - box is already surrounded with php tag - modified query - but its not helping - can you suggest an edit in the code

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.