Jump to content

[SOLVED] A Modulus among Us


tigomark

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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];
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.