Hi This is driving me crazy. Here is my problem. I am developing a webpage that has 7 links, in the content area of the page. The links represent days of the week. Like Mon 12th Tue 13th Wed 14th Thu 15th Fri 16th Sat 17th Sun 18th When a user clicks a link, I want the selected link to change colour. All other links should remain the same colour, only changing when selected. Then going back to default colour when another link is selected. The links pass a query string to get data from a MySql database. If I was developing a static html page this would be no problem at all. As I would be able to uniquely identify each page and style the links accordingly. However these links are dynamically generated using PHP built date function. I have read countless online tutorials to try and solve this problem but unfortunately almost all of these are based static html pages where each page can be uniquely identified. I am seriously stuck and will appreciate assistance. Thanks in advance. Here is the code of my test page. <?php for($time = strtotime('-2 days'), $i=0; $i < 6; $time = strtotime('-1 days', $time), $i++) { if($i != 0) echo " "; echo '<a href="/catch-up/?date=' . date("d-m-Y", $time) . '">' . date("D jS", $time) . "</a>\n"; } ?>
hmmm... wouldn't a <style> tag work ? <style> a { color: red; } a:hover { color:black; } </style> Code (markup): Have you tried that?
Hi Thanks for the reply. I want the link to change colour, I am not looking for a hover. Also this is dynamic link so am not sure how you would go about styling it.
<?php for ($time = strtotime('-2 days'), $i=0; $i < 6; $time = strtotime('-1 days', $time), $i++) { $date = date("d-m-Y", $time); echo '<a href="/catch-up/?date='.$date.'"'. ((isset($_GET['date']) && $_GET['date'] == $date) ? ' style="color:#f00"' : '') .'>' . date("D jS", $time) . "</a>\n"; echo ' '; } ?> PHP: