SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: Menu problem

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2007
    Location
    Oslo, Norway
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Menu problem

    Hi folks,

    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:
    PHP Code:
    <ul id="dhtmlgoodies_listMenu">
    <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 />
    <?php
    $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";
        
    $menu_final .="<ul>";
        
    $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";
        endwhile;
        
    $menu_final .="</ul></li>";
    endwhile;
    echo 
    $menu_final;
    ?>
    </ul>
    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:
    http://egodesign.no/js/listmenu.js

    Thanks for any help.

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,331
    Mentioned
    463 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by hoeiesta View Post
    the active link doesn't work properly.
    It looks like it works fine in both examples, unless I'm missing something.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2007
    Location
    Oslo, Norway
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    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.

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,331
    Mentioned
    463 Post(s)
    Tagged
    8 Thread(s)
    Oh, I see. Looks indeed like a PHP problem then (often it's just CSS). I didn't click down far enough.

  5. #5
    Non-Member
    Join Date
    Oct 2007
    Posts
    363
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    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.

  6. #6
    SitePoint Enthusiast
    Join Date
    May 2007
    Location
    Oslo, Norway
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, thank you for the tip.
    I will look into PDO, but still the menu won't work I guess?

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2007
    Location
    Oslo, Norway
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can anyone see the problem with the menu except the PDO?

  8. #8
    SitePoint Enthusiast
    Join Date
    May 2007
    Location
    Oslo, Norway
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone? Please.
    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

  9. #9
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    As argh says, look into using PDO. That said, to actually answer your question...well, we cant answer your question.

    Your problem lies in Javascript, not PHP, because it's the Javascript that's adding the menu class to the link.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  10. #10
    SitePoint Enthusiast
    Join Date
    May 2007
    Location
    Oslo, Norway
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •