shedokan Posted November 28, 2007 Share Posted November 28, 2007 I have this links: <a href='page.php?id=1'>link1</a> | <a href='page.php?id=2'>link2</a> | <a href='page.php?id=3'>link3</a> | <a href='page.php?id=4'>link4</a> and I would like that if id=1 so link1 is disabled. how can I do it the best way? Quote Link to comment https://forums.phpfreaks.com/topic/79168-solved-what-is-the-best-way-to-do-this/ Share on other sites More sharing options...
pocobueno1388 Posted November 28, 2007 Share Posted November 28, 2007 You could do something like this... <?php for($i=1; $i<=4; $i++){ if ($i == 1) echo 'Link'.$i.' | '; else echo "<a href='page.php?id=$i'>link$i</a> | "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79168-solved-what-is-the-best-way-to-do-this/#findComment-400716 Share on other sites More sharing options...
shedokan Posted November 28, 2007 Author Share Posted November 28, 2007 bt what if I want differet names fo each link? Quote Link to comment https://forums.phpfreaks.com/topic/79168-solved-what-is-the-best-way-to-do-this/#findComment-400732 Share on other sites More sharing options...
pocobueno1388 Posted November 28, 2007 Share Posted November 28, 2007 First off, how are you determining what the name of the link is? Are you pulling them from the database, an array, or what? Quote Link to comment https://forums.phpfreaks.com/topic/79168-solved-what-is-the-best-way-to-do-this/#findComment-400746 Share on other sites More sharing options...
shedokan Posted November 28, 2007 Author Share Posted November 28, 2007 from an array. and I figured it out myself. here's what I got bt is there a better way of doing this? <?php $ctgs = array("hello", "test", "apple", "pizza"); for($i=0; $i<=3; $i++){ $name = $ctgs[$i]; if ($name == "test") echo '<b>'.$name.'</b> | '; else echo "<a href='page.php?id=$name'>$name</a> | "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79168-solved-what-is-the-best-way-to-do-this/#findComment-400748 Share on other sites More sharing options...
pocobueno1388 Posted November 28, 2007 Share Posted November 28, 2007 Nope, your way works just fine =] Quote Link to comment https://forums.phpfreaks.com/topic/79168-solved-what-is-the-best-way-to-do-this/#findComment-400751 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.