Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Too many if() statements - this feels wrong



3:29 am on Nov 4, 2008 (gmt 0)

10+ Year Member

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>';
if (isset($HTTP_GET_VARS['manid']) && $themanquer['similar_country'] !==''){
if ($themanquer['similar_country'] =='CAN'){
}elseif ($themanquer['similar_country'] =='FIN'){
}elseif ($themanquer['similar_country'] =='GER'){
}elseif ($themanquer['similar_country'] =='NOR'){
}elseif ($themanquer['similar_country'] =='SWE'){
}elseif ($themanquer['similar_country'] =='USA'){
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 />';
echo'Try other <a href="/type-'.$themanquer['similar_type'].'">'.$themanquer['similar_type'],'</a> stuff.<br/>';


4:28 am on Nov 4, 2008 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

you could try

switch() [php.net]


7:13 am on Nov 4, 2008 (gmt 0)

10+ Year Member

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

Featured Threads

Hot Threads This Week

Hot Threads This Month