1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to highlight a dynamic link when clicked?

Discussion in 'PHP' started by jamjam1, Jul 15, 2010.

  1. #1
    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.
    SEMrush
    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 "&nbsp;&nbsp;";

    echo '<a href="/catch-up/?date=' . date("d-m-Y", $time) . '">' . date("D jS", $time) . "</a>\n";
    }
    ?>
     
    jamjam1, Jul 15, 2010 IP
    SEMrush
  2. killerj

    killerj Active Member

    Messages:
    765
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    95
    #2
    hmmm... wouldn't a <style> tag work ?
     
    <style>
    a {
    color: red;
    }
    
    a:hover {
    color:black;
    }
    </style>
    Code (markup):
    Have you tried that?
     
    killerj, Jul 15, 2010 IP
  3. jamjam1

    jamjam1 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.
     
    jamjam1, Jul 15, 2010 IP
  4. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    <?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 '&nbsp;&nbsp;';
    
    }
    ?>
    
    PHP:
     
    Deacalion, Jul 15, 2010 IP
  5. jamjam1

    jamjam1 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Wow.

    That's great it works perfectly. Thank You
     
    jamjam1, Jul 15, 2010 IP