Jump to content

Create id in <a> link with an if statement ?


ttmt

Recommended Posts

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]

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.