subhra subhra - 5 months ago 6
CSS Question

How to add css properties inside the PHP tag

I need one help.i need to restrict some css display property with PHP condition.I am explaining my code below.

<div style="width:24%; float:left; padding:10px;display:none;" id="compid">Select Company :


Here initially my div's css property
is there.But i need to
this using some php condition like below.

<?php if($getcustomerobj->companypro == 1 and $_REQUEST['edit']!=""){display:block}else{display:none} ?>

I need to put the above condition inside the style properties.Please help me how to do it proper way.


you can instanciate your display value before outputing :

$display = ($getcustomerobj->companypro == 1 && $_REQUEST['edit']!="") ? 'block' : 'none';

<div style="width:24%; float:left; padding:10px;display:<?= $display ?>;" id="compid">Select Company :

If you want to mix php and html, you can use php tags inside html :

<p><?php echo $something ?></p>

or short tags if enabled on your server

<p><?= $something ?></p>