Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Senior Member Blackhawk095's Avatar
    Join Date
    May 2011
    Location
    Kentucky (USA)
    Posts
    384
    Member #
    27969
    Liked
    45 times
    I'm working on a database driven drop down menu.

    MY GOAL

    This menu will show a tutorial name. When you hover over that name, a list will drop down that shows all of the tutorials that are under the same sub category.

    PROBLEM

    I need to compare the sub category value of the current tutorial, with the sub category values of the rest of the tutorials.

    I have created a semi working script, but it would only work if I use an IF statement to directly compare the sub categories to a specific sub category. Obviously, these sub categories will change, so that idea won't work.

    I can't figure out how to compare a table column ($row['subCategory']) with another when they have the exact same name.

    If you fix the script, I would like more than a solution. Please explain how you fixed it and why you approached the solution in that way.

    Here is the script:

    PHP Code:

    <?php
        $con 
    mysql_connect($mysql_host$mysql_user$mysql_password);
    mysql_select_db($mysql_database);

    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("my_db"$con);

    $p $_GET['p'];

    $result mysql_query("SELECT * FROM tutorials WHERE tutorialID='$p'");  //selects the information that corresponds with the selected tutorial by its ID

    while($row mysql_fetch_array($result)) {  //The SPAN tags below mark the tutorial name that holds the drop down menu
                
    echo '
                <li><a href="">' 
    $row['category'] . '</a></li>
                <li class="sub_nav_no_link"><a>»</a></li>
                <li><a href="' 
    $row['subCategory'] . '.php" target="_parent" title="' $row['subCategory'] . '">' $row['subCategory'] . '</a></li>
                <li class="sub_nav_no_link"><a>»</a></li>
                <li><span><a href="tutorials.php?p=' 
    $row['tutorialID'] . '" target="_parent" title="' $row['pageTitle'] . '">' $row['pageTitle'] . '</a></span>'
    }
    ?>
                    <ul>
    <?php
    // The script below is the section that needs to be changed
    $result mysql_query("SELECT * FROM tutorials " );

    while(
    $row mysql_fetch_array($result)) {
              If(
    $row['subCategory'] == 'Computer Maintenance') { //echoing out tutorials that have the sub category of Computer Maintenance
            
    echo '
                        <li><a href="tutorials.php?p=' 
    $row['tutorialID'] . '" target="_parent" title"'$row['pageTitle'] . '>' $row['pageTitle'] . '</a></li>';
              }
    }
    ?>
                    </ul>
                </li>
                        </ul>
                    </div>
    </div>
    [COLOR=rgb(0, 51, 102)]Student Web Designer[/COLOR]
    [COLOR=rgb(0, 51, 102)]If you thought something I said was helpful. LIKE IT![/COLOR]

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    I have a possible AJAX/MySQL solution for you.
    It involves creating a new table that contains the menu structure ... either 2-level or 3-level.

    Here is the free script and demo:
    http://www.blueicestudios.com/chaine...hp-mysql-ajax/

    The script is free, but they do have a special "wizard" for sale.
    You don't need the generator tool, but you have to realize that all
    of the menu and submenu selections are stored in a MySQL table,
    so you'll need to edit that table when your selections change.
    That's what the tool does (I think).

    I suppose you could use a simpler flat-file database, and don't use AJAX,
    but when you see the demo, you'll see how nice it looks.


  4. #3
    Senior Member medlington's Avatar
    Join Date
    Nov 2005
    Location
    Sheffield, UK
    Posts
    377
    Member #
    11968
    Liked
    4 times
    Just a thought but cant you read the info into separate variables and then you can compare them?

    first SQL query
    Code:
    $variable1 = $row['subCategory']
    then second SQL query
    Code:
    $variable2 = $row['subCategory']
    Then you have the info stored in 2 different variables to do what you want with them

  5. #4
    Senior Member Ganners's Avatar
    Join Date
    Feb 2011
    Location
    United Kingdom
    Posts
    415
    Member #
    27007
    Liked
    92 times
    You should be trying to accomplish as much of this with MySQL as possible. So surely all you need to do is SELECT * FROM tutorials WHERE category = '{$category_id}' for each category and add it to that object or array.

    If you provide your SQL dump of the database I'd be able to rewrite it for you if you aren't sure.
    Mark Gannaway Software Developer

    Recent Experiments
    - Backpropogation Neural Network language solving (http://ann.ganners.co.uk/)
    - Animated image to ASCII (http://google.ganners.co.uk/)
    - 3D Paper Characters (http://cybergame.ganners.co.uk/)
    - Anagram solving (http://roflol.co.uk/)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:23 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com