ttmt Posted March 22, 2011 Share Posted March 22, 2011 Hi all I haven't used PHP for a while so I'm stuck on something that seems simple. I have a list of nav links created in a while loop, I want to add an id="selected" to the <a> link that is selected. I can check that it's selected with if( $row[1] == $pageName['words']){ id=''selected" } How can I use this to set the id [code] <ul> <?php while($row = mysql_fetch_array($result1)){ //if($row[1] != $pageName['words']){// this will take out the gallery that is showing form the list ?> <li><a href="gallery.php?photo_id=<?php echo $row[0]?>" id=""><?php echo $row[1];?></a></li> <?php //} } ?> </ul> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/231400-create-id-in-link-with-an-if-statement/ Share on other sites More sharing options...
ttmt Posted March 22, 2011 Author Share Posted March 22, 2011 Done it Sorry, should have waited and thought about it bit. Is this the best way. <ul> <?php while($row = mysql_fetch_array($result1)){ //if($row[1] != $pageName['words']){// this will take out the gallery that is showing form the list ?> <li><a href="gallery.php?photo_id=<?php echo $row[0]?>" id="<?php if($row[1] == $pageName['words']){ echo "sel";}?>"><?php echo $row[1];?></a></li> <?php //} } ?> </ul> Quote Link to comment https://forums.phpfreaks.com/topic/231400-create-id-in-link-with-an-if-statement/#findComment-1190848 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.