StefanRSA Posted November 12, 2009 Share Posted November 12, 2009 I am not sure how this should work but am sure its got something to do with arrays. $activetab=$_GET['countrytabs']; $atabname[0]='MY ADS'; $alink[0]='member/member.php?adminads=true&countrytabs=0'; $atabname[1]='ACCOUNT DETAILS'; $alink[1]='member/member.php?adminads=true&countrytabs=1'; $atabname=[2]'TAGGED ADS'; $alink=[2]'member/member.php?adminads=true&countrytabs=2'; How do I display or echo only those links that is not given by $activetab ? In other words If $activetab==0 I want only to echo $atabname[1]='ACCOUNT DETAILS'; $alink[1]='member/member.php?adminads=true&countrytabs=1'; $atabname=[2]'TAGGED ADS'; $alink=[2]'member/member.php?adminads=true&countrytabs=2'; and so on. I can hardcode this but know there should be a short way in doing this seeing that there is a lot of coding to be done if I have say 20 entries in an array but am not sure how? Example of my hardcoded version: $activetab=$_GET['countrytabs']; $atabname[0]='MY ADS'; $alink[0]='member/member.php?adminads=true&countrytabs=0'; $atabname[1]='ACCOUNT DETAILS'; $alink[1]='member/member.php?adminads=true&countrytabs=1'; $atabname=[2]'TAGGED ADS'; $alink=[2]'member/member.php?adminads=true&countrytabs=2'; IF ($activetab==0){ echo $atabname[1]; echo $alink[1]; echo $atabname[2]; echo $alink[2]; } else if ($activetab==1){ echo $atabname[0]; echo $alink[0]; echo $atabname[2]; echo $alink[2]; } else { echo $atabname[0]; echo $alink[0]; echo $atabname[1]; echo $alink[1]; } Can anybody please help? Quote Link to comment https://forums.phpfreaks.com/topic/181296-solved-array-problem/ Share on other sites More sharing options...
sasa Posted November 12, 2009 Share Posted November 12, 2009 try <?php $activetab=$_GET['countrytabs']; $atabname[0]='MY ADS'; $alink[0]='member/member.php?adminads=true&countrytabs=0'; $atabname[1]='ACCOUNT DETAILS'; $alink[1]='member/member.php?adminads=true&countrytabs=1'; $atabname[2]='TAGGED ADS'; $alink[2]='member/member.php?adminads=true&countrytabs=2'; foreach ($atabname as $key => $name){ if ($key != $activetab){ echo $name, ' - ', $alink[$key], "<br />\n"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/181296-solved-array-problem/#findComment-956371 Share on other sites More sharing options...
StefanRSA Posted November 12, 2009 Author Share Posted November 12, 2009 SWEET! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/181296-solved-array-problem/#findComment-956373 Share on other sites More sharing options...
StefanRSA Posted November 12, 2009 Author Share Posted November 12, 2009 Sasa, I am not sure why, but this code does not echo anything... Doesn't matter if $activetab is 0,1,2 or any other number? Quote Link to comment https://forums.phpfreaks.com/topic/181296-solved-array-problem/#findComment-956396 Share on other sites More sharing options...
StefanRSA Posted November 13, 2009 Author Share Posted November 13, 2009 Fixed it, had a spelling mistake in my code. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/181296-solved-array-problem/#findComment-956672 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.