tags:

views:

44

answers:

1

I'm trying to display a link orange when clicked but for some reason I can get it to work when using PHP can some one help me correct this problem?

Here is the PHP code.

function category_tree( $parent = 0, $parent_url = '' ){
    $page_url = current_page_url();//grabs url address

    echo "<ol>";
    $mysqli = mysqli_connect("localhost", "root", "", "sitename");
    $q = sprintf("SELECT id, category, url FROM categories WHERE parent_id = %d ORDER BY category asc", $parent);
    $r = mysqli_query($mysqli, $q);
    while($rs = mysqli_fetch_assoc($r) ){
        $url = $parent_url . $rs['url'];
        echo '<li> <a href="' . $url . '" title="' . $rs['category'] . ' Category Link" ';

        if($url == $page_url){
            echo 'style="color: orange;"';
        }

        echo '>' . $rs['category'] . '</a> </li>';
        category_tree($rs['id'], $url);
    }
    mysqli_free_result( $r );
    echo "</ol>";
}

Output:

Arts & Humanities
Autos
Business
Computers & Technology
Creative Writing
Education
Entertainment
+2  A: 

After reading your code, I would try to print the values of $url and $page_url and see if they are ever the same. Also have a look at your output and see if style="color:orange;" is ever being outputted to the browser. If the link are not turning orange, I would imagine that your condition of "($url == $page_url)" never returns true.

Older answer

This isn't exactly a PHP problem, it's more to do with the CSS. If you have a CSS file you can add the following to make it work properly:

a:link{
   color:black;
}
a:visited{
   color:orange;
}

If you need to create a place to put your CSS you can add the following code to your HTML:

<style type="text/css">
/* CSS CODE HERE */
</style>
Sam152
They are the same values $url and $page_url.
HiThere
@Sam152 This did not work at all:(
HiThere
Can you post the output of the browser?
Sam152
Post what output the links urls?
HiThere
Yes, that way you can see if the browser is actually adding the orange css color stuff or its not even getting to that point in the PHP.
Sam152
I hope the edit is what you wanted no color change at all.
HiThere
You need to hit "view source" and then paste the raw output of the browser.
Sam152
The link code is still the same.
HiThere