mattheww Posted December 11, 2009 Share Posted December 11, 2009 I want to do the sort of formatting like in Microsoft excel. I want to do where for example, I typed in "1" and it turned red, I typed in "2" It turned blue Is it possible? I presuming it is... but HOW, I'm not sure how to go about this... Quote Link to comment https://forums.phpfreaks.com/topic/184821-php-conditional-formatting/ Share on other sites More sharing options...
ignace Posted December 11, 2009 Share Posted December 11, 2009 The correct answer depens on what your cell looks like when you type in 3 and 4. If red and blue are the only possible colors you could use something like: $value % 2 === 0 ? 'blue' : 'red' If the colors keep changing: $colors = array('red', 'blue', 'orange', .., 'purple'); print $colors[$value - 1]; Quote Link to comment https://forums.phpfreaks.com/topic/184821-php-conditional-formatting/#findComment-975697 Share on other sites More sharing options...
mattheww Posted December 11, 2009 Author Share Posted December 11, 2009 I see that's useful... and what if i was to type in exact words, like if a MySQL result returns "hello" and I wanted the php code to only change a word/exact phrase red if it said "Hello" How would I do that? Quote Link to comment https://forums.phpfreaks.com/topic/184821-php-conditional-formatting/#findComment-975701 Share on other sites More sharing options...
chaking Posted December 11, 2009 Share Posted December 11, 2009 <?php $a = "Hello"; <-mysql result $b= "Hello"; <-string you want to match if ($a == $b){ $a = "<font color = red>".$a."</font>"; } ?> Might not be the prettiest way of doing it, but it works. Quote Link to comment https://forums.phpfreaks.com/topic/184821-php-conditional-formatting/#findComment-975714 Share on other sites More sharing options...
mattheww Posted December 12, 2009 Author Share Posted December 12, 2009 Thankyou chaking! Quote Link to comment https://forums.phpfreaks.com/topic/184821-php-conditional-formatting/#findComment-975716 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.