I have a "strange" problem with a menu. The problem is the "active" state on the clients in the menu.
The code selects subcategories and clients from the database and orders the clients by a cli_order field.
I want the cli_order to sort ascending but when I do, the active link doesn't work properly. If I change the order to descending then it works as it should do.
The page shows correct content all the time, it's only the "active" state that's not working.
Here is the menu code:
Here is the link to the page with ascending clients: http://egodesign.no/portfolio/?sid=6&cid=12
<li style="margin-bottom: 3px;"><a href='/about/#'>Om Ego Design</a></li>
<li style="margin-bottom: 3px;"><a href='/contact/#'>Kontakt</a></li><br />
$sec_id = 3; // portfolio sector id
$sql = "SELECT id, no_name FROM sector WHERE parentid=(SELECT id FROM sector WHERE id=$sec_id) ORDER BY cat_order ASC";
$link = mysql_query($sql);
$menu_final = '';
while( list($sid, $no_name) = mysql_fetch_array($link) ):
$category_link = '<a href="#">' . $no_name . '</a>';
$menu_final .="<li>\t" . $category_link . "\n";
$sql = "SELECT DISTINCT clients.id, clients.name, clients.cli_order, content.subsectorid FROM clients, content WHERE clients.id=content.clientid AND content.sectorid=$sec_id AND content.subsectorid=$sid ORDER BY clients.cli_order ASC";
$link2 = mysql_query($sql);
while( $row = mysql_fetch_array($link2) ):
$client_link = '<a href="/portfolio/?sid=' . $row['subsectorid']. '&cid=' . $row['id'] . '">' . $row['name'] . ' </a>';
$menu_final .= "<li>\t" . $client_link . "</li>\n";
Here is the link when cli_order is changed to DESC: http://egodesign.no/portfolio/index2.php?sid=6&cid=12
I use listmenu.js to generate the code:
Thanks for any help.
It looks like it works fine in both examples, unless I'm missing something.
Originally Posted by hoeiesta
Thanks for your reply.
No, it doesn't work in my browsers. The active link is yellow background and black, bold text.
In the first link (http://egodesign.no/portfolio/?sid=6&cid=16) it stops after the two first clients. When you click the third customer the active state goes back the first client in the list.
In the second link (http://egodesign.no/portfolio/index2.php?sid=6&cid=16) it gets correct but the clients are reverse of the order I want.
Oh, I see. Looks indeed like a PHP problem then (often it's just CSS). I didn't click down far enough. :)
You've got bigger problems than just your menu here. Code is very messy for a start, and then on top of that you're completely open to sql injection attacks. If I were so inclined, I could literally erase your entire database just by visiting your site and typing in a bit of code in the url. You should look into PDO prepared statements and fix immediately.
Ok, thank you for the tip.
I will look into PDO, but still the menu won't work I guess?
Can anyone see the problem with the menu except the PDO?
I have put the menu and script on another server and there it works fine.
Can it be something in the server config? The one that works run 5.3.3-7+squeeze14 / mysql 5.1.66.
The not working one runs 5.5.17-1~dotdeb.0 / mysqlnd 5.0.8-dev - 20102224
As argh says, look into using PDO. That said, to actually answer your question...well, we cant answer your question.