...

View Full Version : Can someone help me with my PHP calculator?



Rachel_R
11-13-2011, 09:48 AM
if($num%2==0){
$html="<span style='color:purple;'>".$num.''</span>";
/*divide by 2 without rest = even*/
}
else{
$html="<span style='color:pink;'>".$num.''</span>";
/*divide by 2 with rest 1 = odd*/
}

sunfighter
11-14-2011, 12:00 AM
If all you want is to set a variable then you will see nothing. If you want an output to look at :

<?php
$num = 51;

if($num%2 == 0)
{
echo "<span style='color:purple;'>$num</span>";
/*divide by 2 without rest = even*/
}
else{
echo "<span style='color:black;'>$num</span>";
/*divide by 2 with rest 1 = odd*/
}
?>You need to set the $num variable so the comparison is done.

OR


<?php
$num = 51;

if($num%2 == 0)
{
$html = "<span style='color:purple;'>$num</span>";
/*divide by 2 without rest = even*/
}
else{
$html = "<span style='color:black;'>$num</span>";
/*divide by 2 with rest 1 = odd*/
}
echo $html;
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum