php - if statement not working when table = uri -


i have if statement when mysql table = server uri, changes css class, haven't been able work. here code:

    $adminresults = mysql_query('select * menu_admin position="l"');     $adminresults_array = array();     while ($row = mysql_fetch_assoc($adminresults)) {         $img = $row["img"];         $href = $row["location"];         $text = $row["name"];         $uri = $_server["request_uri"];         if ($href == $uri){         $output .= "<li class='active'><a href='$cfg->wwwroot/{$href}'><p class='cssimg'><img src='$cfg->wwwroot/theme/{$img}'/></p><p class='csstxt'>{$text}</p></a></li>";         } else {     $output .= "<li><a href='$cfg->wwwroot/{$href}'><p class='cssimg'><img src='$cfg->wwwroot/theme/{$img}'/></p><p class='csstxt'>{$text}</p></a></li>";         } } } echo "<link rel='stylesheet' href='/theme/css/styles.css' type='text/css'> <div id='leftmain'> <div class='cssmenu' align='left'> <ul>{$output}</ul> </div> </div>"; 

the location filename or path filename example sitefolder/file.php

i suspect problem $_server["request_uri"] includes slash @ start of uri, whereas $href variable doesn't.

perhaps use ltrim on server uri before comparison. this:

$uri = ltrim($_server["request_uri"],'/'); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -