Help condensing simple code for many items

I have 29 columns in my table/app and I’m using the sc_field_color macro to change their colors based on value.

values:
1 = Yes - green
2 = No - red
3 = N/A - blue

The code below is for 1 column and I have 29! Is there some way to condense all this. I’m no programmer but if pointed in the right direction I can do it. I was thinking FOR loop? What would you all suggest?

if ({item1} == '1')
	{
		sc_field_color("item1", "#00CC00"); //green
		}
elseif ({item1} == '2')
	{
		sc_field_color("item1", "#CC0000"); //red
		}
elseif ({item1} == '3')
	{
		sc_field_color("item1", "#0000FF"); //blue
		}

Untested …

for ($i = 1; $i <= 29; $i++)
{

$fieldname = "{item" . trim($i) . "}";

    switch ($fieldname)
    {
        case 1:
            sc_field_color($fieldname, "00CC00"); // green
            break;
        case 2:
            sc_field_color($fieldname,  "#CC0000"); // red
            break;
        case 3:
           sc_field_color($fieldname, "#0000FF"); // blue
           break;
    }
}

HTH.

Good simple logic but I can’t get it to work. I’ve tried creating a php method and tried it in events with no results. Thanks anyway. I’m not quite sure how to use parameters when creating a method.