Results 1 to 7 of 7
  1. #1
    Member Sharan's Avatar
    Join Date
    May 19th, 2006
    Location
    SW Missouri
    Posts
    54
    Code to create a Nav menu from a category list
    I know how to get a list of unique items from a category column, but is there a way to use php to automatically turn that list into a navigation menu? I would appreciate a little guidance in that area.

    I am not very php literate so if it is possible a small example of the code would help.

    Thanks,
    Sharan

  2. #2
    ABW Ambassador writerguy's Avatar
    Join Date
    January 17th, 2005
    Location
    Springfield, Missouri, USA
    Posts
    3,248
    Quote Originally Posted by Sharan
    I know how to get a list of unique items from a category column, but is there a way to use php to automatically turn that list into a navigation menu? I would appreciate a little guidance in that area.

    I am not very php literate so if it is possible a small example of the code would help.

    Thanks,
    Sharan
    Hi Sharan. I just emailed you something you're welcome to fiddle around with. Don't know how helpful it'll prove, but maybe similar to what you're looking for.
    Generate more fake news.

  3. #3
    ABW Ambassador Doug247's Avatar
    Join Date
    January 18th, 2005
    Location
    DE USA
    Posts
    931
    Here is what I do. This is a quick reply, so if it is not clear let me know.


    PHP Code:
    $queryCategory "SELECT Distinct Category FROM $tablename Where Column1 = '$Column1' AND Category IS NOT NULL ORDER BY Category"
    $resultCategory mysql_query($queryCategory$link) or die("Error in query: $queryCategory. " mysql_error()); 
        while (
    $rowCategory mysql_fetch_array ($resultCategory))
            {
            if (
    $rowCategory[Category] <> '')
                {
                
    $Cat ucwords(stripslashes($rowCategory[Category]));
                
    $CatURL strtolower(str_replace(" ","_",$rowCategory[Category]));
                print (
    "<a href=\"http://Domain/folder/$CatURL.html\">$Cat</a><br>\n");
                }
            } 
    Thanks,
    Doug

  4. #4
    Member Sharan's Avatar
    Join Date
    May 19th, 2006
    Location
    SW Missouri
    Posts
    54
    Gary -- I got your email and responded.

    Doug -- thanks for the code snippet. I tried it and received a couple of errors, but I will play around with it some and see if I can get it to work. I'll keep you updated.

    Thanks,
    Sharan

  5. #5
    ABW Ambassador Doug247's Avatar
    Join Date
    January 18th, 2005
    Location
    DE USA
    Posts
    931
    What errrors did you get?
    Thanks,
    Doug

  6. #6
    Member Sharan's Avatar
    Join Date
    May 19th, 2006
    Location
    SW Missouri
    Posts
    54
    Doug,

    I just now got it to work. At first it was telling me my query was wrong. I was trying to make sure I was asking for the correct column names. In the meantime Gary sent me a code that he had used and it didn't give me exactly what I wanted so I did a little combining of the two of them and now so far the results look like what I was wanting.

    This is what I am using now that seems to be working.
    Code:
    $result = mysql_query("select DISTINCT category from $table ORDER by category ASC") or die (mysql_error());
    while ($row = mysql_fetch_array($result))
    {
    $catname = urlencode($row[category]);
    $CatURL = strtolower(str_replace(" ","_",$row[category]));
    echo "<a href=\"http://site.com/folder/$CatURL.php\">$row[category]</a><br>";
    }
    Thanks Gary and Doug. I'm learning a little more everyday.
    Sharan

  7. #7
    ABW Ambassador Doug247's Avatar
    Join Date
    January 18th, 2005
    Location
    DE USA
    Posts
    931
    I'm learning too. Glad you got it figured out.
    Thanks,
    Doug

  8. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Create multiple index pages per category.
    By jmmktent in forum WebMerge (Fourthworld.com)
    Replies: 2
    Last Post: August 1st, 2007, 01:48 PM
  2. Category menu
    By jackson992 in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: June 26th, 2007, 04:56 PM
  3. Nav Bar - How to highlight current category?
    By Aiyo in forum WebMerge (Fourthworld.com)
    Replies: 3
    Last Post: April 18th, 2005, 02:15 PM
  4. how do I create a new index page for each product category?
    By pw3909 in forum WebMerge (Fourthworld.com)
    Replies: 2
    Last Post: May 2nd, 2004, 08:21 AM

Posting Permissions

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