trying to make a link background color dynamic when that lin

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Teli
Forum Newbie
Posts: 5
Joined: Fri May 08, 2009 10:52 am

trying to make a link background color dynamic when that lin

Post by Teli »

Hello-

I am new to the forum, Hello Everyone.

I am trying to make a background color change on my link menu, however the link menu is dynamically generated. The code for the link menu is stated below.

as you will notice the link menu is located in a while loop. the page never changes in the http link. Which for me has made it more difficult to make it noticeable on which page the user is on.

Code: Select all

 
While loop {
 
echo "<table height='1%' width='225px' border='0' style='background-color:#336699'><tr><td valign='middle'><a class='linkchange' href='index_credit_card.php?categories=$row[0]&record_id=0&page=0'><font style='color:white;font-size:13px;font-family:arial;text-transform:uppercase'>&nbsp;&nbsp;<strong>$row7[0]</strong></font></a> (";
 
}
 
Basically, i think i need to figure out how to make the background color change in a <td> for the links, moreover these links do not actually change the page because the page remains the same in the http link, it the content that changes.

i also tried making active links in css but then it changes ever link that i click on and does not remove the previous one i was on.

thanks for your time,

Teli
Last edited by Benjamin on Fri May 08, 2009 11:20 am, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: trying to make a link background color dynamic when that lin

Post by Christopher »

I would probably be better to create a little style sheet:

Code: Select all

 
echo '<style>
.mylink {
     color:white;
     font-size:13px;
     font-family:arial;
     font-weight:bold;
     text-transform:uppercase;
     }
</style>';
 
While loop {
 
echo "<table height='1%' width='225px' border='0' style='background-color:#336699'><tr><td valign='middle'><a class='linkchange' href='index_credit_card.php?categories=$row[0]&record_id=0&page=0' class=\"mylink\">&nbsp;&nbsp;{$row7[0]}</a> (";
 
}
Then you could add hover, visited, etc. styles to style for the link.
(#10850)
Teli
Forum Newbie
Posts: 5
Joined: Fri May 08, 2009 10:52 am

Re: trying to make a link background color dynamic when that lin

Post by Teli »

Hello -

Thanks for the reply Arborint, however, i tried this and the result is that when i set the links to active it does not deselect the last link i was on. So they all get a background color.

The idea of the style does not work, I have been looking on line and have read a lot about the style however, i think i need something with php or javascript.

Thanks for your help.

Any other ideas would be appreciated.

Thanks.

Teli
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: trying to make a link background color dynamic when that lin

Post by Christopher »

So does this code do what you want it to?

Code: Select all

<html>
<head>
</head>
<body>
<style>
.mylink {
    color:white;
    font-size:13px;
    font-family:arial;
    font-weight:bold;
    text-transform:uppercase;
    }
.mylink:hover {
    color:yellow;
    }
 </style>
<table height='1%' width='225px' border='0' style='background-color:#336699'>
<tr>
<td valign='middle'><a href='index_credit_card.php?categories=$row[0]&record_id=0&page=0' class="mylink">&nbsp;&nbsp;{$row7[0]}</a>
</td>
</tr>
<tr>
<td valign='middle'><a href='index_credit_card.php?categories=$row[0]&record_id=0&page=0' class="mylink">&nbsp;&nbsp;{$row7[0]}</a>
</td>
</tr>
</table>
</body>
</html>
(#10850)
Teli
Forum Newbie
Posts: 5
Joined: Fri May 08, 2009 10:52 am

Re: trying to make a link background color dynamic when that lin

Post by Teli »

Hello -

No this code does not do what I want.

I want the active to show that the link is active when a person clicks on it and when they move to an other link, in the menu that the previous one becomes disactivtaed and the new one becomes highlight, this why people know which link they are on.

Thanks.

Teli
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: trying to make a link background color dynamic when that lin

Post by Christopher »

So you want the link they clicked to get to this page to be highlighted?
(#10850)
Teli
Forum Newbie
Posts: 5
Joined: Fri May 08, 2009 10:52 am

Re: trying to make a link background color dynamic when that lin

Post by Teli »

Hello -

Almost, the page in the href never changes. It just changes the data from the database which is displayed, so the actual page name of the links do not change its just the row id that changes.

as seen here, its always the index_credit_Card.php page its just he categories that change.

href='index_credit_card.php?categories=$row[0]&record_id=0&page=0'>

hope this helps

Thanks.
Teli
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: trying to make a link background color dynamic when that lin

Post by Christopher »

No, sorry I am not understanding. It is the highlighting that is not right or the URLs? In the example I posted, only the link you are mousing over is highlighted. I am not clear what activated and deactivated mean to you?
(#10850)
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: trying to make a link background color dynamic when that lin

Post by divito »

You're going to have to be way more specific Teli.

Do you want the link to be highlighted when someone puts their cursor over it?
Do you want that link to be a different color right when they click the link?
Do you want that link to be a different color after they have clicked the link and are on the new page?
Teli
Forum Newbie
Posts: 5
Joined: Fri May 08, 2009 10:52 am

Re: trying to make a link background color dynamic when that lin

Post by Teli »

Hello

Thanks for your help so far.

Do you want that link to be a different color after they have clicked the link and are on the new page?

Yes, I want this one but remember the links are not changing the page if you read the prior post you will see that the category id changes not the page, the index_credit_Card.php does not change.

I hope this helps.

Thanks for your time,
Teli
Post Reply