tigomark Posted January 30, 2008 Share Posted January 30, 2008 Hello, I am having trouble adjusting a modulus that I have created for ($i=1; $i<=11; $i++){ $field = 'zone'.($i).'_id'; $this->zoneColors[$i] = $row[$field] % 11 ; When I build my switch function showShapeColor($color){ strtolower($color); switch($color){ case 1: return "#ff0000"; break; case 2: return "#0000ff"; break; case 3: return "#00ff00"; break; case 4: return "#FF6600"; break; case 5: return "#CC00CC"; break; case 6: return "#996600"; break; case 7: return "#FFCC00"; break; case 8: return "#5a6d24"; break; case 9: return "#CC9999"; break; case 10: return "#CDDF60"; break; case 11: return "#44e2f1"; break; case 12: return "#4feff1"; break; default: return "#ffffff"; break; } } Occasionally I will have overlapping values ie int(5) may be attached to more than one record thus giving 2 rows the same color. I need to build a way to check for this so that if that happens one of the 5's will be #f5f5f5 and the other will be the regular color. Kind of lost on how. Thanks Quote Link to comment Share on other sites More sharing options...
tigomark Posted January 30, 2008 Author Share Posted January 30, 2008 I figured it out for ($j = 1; $j <= 11; $j++){ if(($entry->zoneColors[$j] == $entry->zoneColors[$j + 1]) && ($entry->zoneColors[$j] != 0)){ $entry->zoneColors[$j] = 12; } } I just needed to compare the array types in the view and then append to the unused 12th color in that instance. Thanks to all who looked at this Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 30, 2008 Share Posted January 30, 2008 You can make that function a LOT easier to manage like this: <?php function showShapeColor($color){ strtolower($color); $colorsAry = ( '0' => "#ffffff", //Default '1' => "#ff0000", '2' => "#0000ff", '3' => "#00ff00", '4' => "#FF6600", '5' => "#CC00CC", '6' => "#996600", '7' => "#FFCC00", '8' => "#5a6d24", '9' => "#CC9999", '10' => "#CDDF60", '11' => "#4feff1", '12' => "#ff0000" ); //Set to default if not valid if (!in_array($color, $colorsAry) { $color = 0; } else return $colorsAry[$color]; } ?> Quote Link to comment 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.