PHP link problem
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
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>
精彩评论