| Too many if() statements - this feels wrong
|
jake66

msg:3779658 | 3:29 am on Nov 4, 2008 (gmt 0) | This sure looks like a lot of if() statements, but it does exactly what I want it to do. Is this too much, or is there a way to condense it? if (isset($HTTP_GET_VARS['category'])){ echo'You may also like <a href="' . tep_href_link(SIMILAR) . '">these</a>'; }else{ if (isset($HTTP_GET_VARS['manid']) && $themanquer['similar_country'] !==''){ if ($themanquer['similar_country'] =='CAN'){ $location='Canadian'; }elseif ($themanquer['similar_country'] =='FIN'){ $location='Finnish'; }elseif ($themanquer['similar_country'] =='GER'){ $location='German'; }elseif ($themanquer['similar_country'] =='NOR'){ $location='Norwegian'; }elseif ($themanquer['similar_country'] =='SWE'){ $location='Swedish'; }elseif ($themanquer['similar_country'] =='USA'){ $location='American'; } echo'Can\'t find it? Try more <a href="' . tep_href_link('loc-'.$themanquer['similar_country']) . '-' . $themanquer['similar_type'].'">'.$location.' ' .$themanquer['similar_type'].'</a>, '; echo'and <a href="/type-'.$themanquer['similar_type'].'">'.$themanquer['similar_type'],'</a><br />'; }else{ echo'Try other <a href="/type-'.$themanquer['similar_type'].'">'.$themanquer['similar_type'],'</a> stuff.<br/>'; } } |
|
|
jatar_k

msg:3779680 | 4:28 am on Nov 4, 2008 (gmt 0) | you could try switch() [php.net]
|
adb64

msg:3779734 | 7:13 am on Nov 4, 2008 (gmt 0) | Or try this Define an array somewhere at the top of your PHP file:
$Countries = array( 'CAN' => 'Canadian', 'FIN' => 'Finnish', 'GER' => 'German', 'NOR' => 'Norwegian', 'SWE' => 'Swedish', 'USA' => 'American');
And where you now have all the if() statements:
if (isset($Countries[$themanquer['similar_country']])) { $location = $Countries[$themanquer['similar_country']]; }
|
|
|