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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.