Forum Moderators: coopster

Message Too Old, No Replies

divs

         

ayushchd

5:30 am on May 10, 2007 (gmt 0)

10+ Year Member



hi..
i m looking to change the class of a div according to a php condition.

I have two variables $mycount and $val..Wht is want is that if $mycount > $val then : <div class = "loss"> <? echo $difference;?> </div>

And if $val > $mycount then : <div class ="gain"> <? echo $difference;?> </div>

I dunno how to do it

leadegroot

6:40 am on May 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is a fairly basic question.
One solution is a simple:

if ($mycount > $val) {
echo '<div class = "loss">'.$difference.'</div>';
} else {
echo '<div class ="gain">'.$difference.'</div>';
}

or you could remove the redundancy and put something like:


echo '<div class = "';
if ($mycount > $val) {
echo 'loss';
} else {
echo 'gain';
}
echo '">'.$difference.'</div>';

ayushchd

7:34 am on May 10, 2007 (gmt 0)

10+ Year Member



After I posted, I myself drew out a solution to this fairly basic question.

I have this now and is working perfectly :)

<div <? if ($difference >= 0) {?> id="gain" <? } else {?> id ="loss" <? }?>>
<h2>
<? if ($difference == 0) {
echo " Gain / Loss : ". $difference;
} else if ($difference > 0) {
echo " Gain : ". $difference;
} else if ($difference < 0) {
echo " Loss : " . $difference;
}?>

</h2>


</div>

Ayush. And I asked a basic question coz my age is only 15 and m learning php