Hi Currently I am using this <span class="bits"><?php if ($row_rs_newprop['beds'] > 0){echo $tag2, $row_rs_newprop['beds'],", ";} ?></span> and of course the span still shows, how do I make it so the css wont show at all if the result is negative. Hope this makes sense Jamie
try this: <?php if ($row_rs_newprop['beds'] > 0) { print "<span class=\"bits\">"; echo $tag2, $row_rs_newprop['beds'],", "; print "</span>"; } ?> Code (markup):
Just set the variables in an if statement before you echo them: <?php if ($row_rs_newprop['beds'] > 0) { $tag2 = ;// whatever you want it to equal; $class = "bits"; } ?> <span class="<?=$class;?>"><?= $tag2; ?></span> Code (markup):
If you want to do it simpler, you could do this. <span class="<? echo ($row_rs_newprop['beds'] > 0) ? "bits" : "" ?>"></span> PHP: Thats using ternary operators
that doesn't make any sense in this case, there's no alternate or 'else' condition, so a ternary operator is unnecessary
It makes perfect sense. It uses less code than all the other examples. A false result isn't entirely necessary, but it gets the job get more efficiently and faster. Using a whole if statement and putting it to a var, then echoing the var, now thats unnecessary