hoeiesta — 2012-12-01T10:24:09-05:00 — #1
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:
<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>\ " . $category_link . "\
$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>\ " . $client_link . "</li>\
Here is the link to the page with ascending clients: http://egodesign.no/portfolio/?sid=6&cid=12
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.
ralphm — 2012-12-02T01:27:32-05:00 — #2
It looks like it works fine in both examples, unless I'm missing something.
hoeiesta — 2012-12-02T02:42:55-05:00 — #3
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.
ralphm — 2012-12-02T04:23:34-05:00 — #4
Oh, I see. Looks indeed like a PHP problem then (often it's just CSS). I didn't click down far enough.
system — 2012-12-02T05:37:31-05:00 — #5
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.
hoeiesta — 2012-12-02T07:52:52-05:00 — #6
Ok, thank you for the tip.
I will look into PDO, but still the menu won't work I guess?
hoeiesta — 2012-12-05T10:05:06-05:00 — #7
Can anyone see the problem with the menu except the PDO?
hoeiesta — 2012-12-06T05:27:10-05:00 — #8
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
starlion — 2012-12-06T09:25:21-05:00 — #9
As argh says, look into using PDO. That said, to actually answer your question...well, we cant answer your question.
hoeiesta — 2012-12-07T06:54:17-05:00 — #10