SitePoint Sponsor

User Tag List

Results 1 to 20 of 20
  1. #1
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone got any ideas, on how to implement something like yahoo? where you have sub-categories, to categories... which can go as deep as the user wonts?


    The method I thought of, was alil long wided.. so im looking for inputs..

    Thanx.
    i dunno...

  2. #2
    SitePoint Zealot Alarion's Avatar
    Join Date
    May 2001
    Location
    Virginia
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    hmmm

    Well, you could maybe have a table designed something like this (this is just a quick layout..):

    Code:
    table links
    -------------------------------
    linkid int(10) not null primary key auto inc
    link_title varchar(50) not null
    link_desc text
    link_url varchar(255) default('none')
    link_iscat enum('yes', 'no')
    parent_id int(10) default(0)
    --------------------------------
    now, what you could then do, is first display all records where link_iscat = yes AND parent_id = 0

    the way I am thinking, this would display all catagories that don't have a parent, thus they should be your top level catagories.
    As well, if you wanted links on this page, you could then display all records where link_iscat = no AND parent_id = 0

    from then on in, each link would have a "?cat=xxxx" appended with the linkid of the current catagory. when the user clicks on that link, you would first display all records where link_iscat = yes AND parent_id = xxxx
    this would show your "sub catagories". After that, I would imagine you want to show any links in this catagory. so you would then display all records where link_iscat = no AND parent_id = xxxx

    now, you may be wondering why to default the link_url to "none". You could just leave it blank with no default I suppose. Doesn't really matter. Anyhow, you don't need a URL in that field for catagories, because you would hardcode a url like "catagorydisplay.php?cat=3" for example.

    you could also split the table up into two tables. One for catagories, and one for links. The same drill-down approach would be valid though. Use a "parentid" column, and whichever catagories don't have a parentid set, are your top-most catagories.

    I hope that helps, or at least gets the juices flowing for you
    -=Alarion=-
    Protollix - Linux hosting from $3.95/m

  3. #3
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey,
    thanx for the help.. that makes sense.. but is a lil more complicated then what i would have liked

    but its way better then what i thought up...
    thanx for the help
    i dunno...

  4. #4
    SitePoint Zealot Alarion's Avatar
    Join Date
    May 2001
    Location
    Virginia
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe, no prob man. If it's confusing you, or won't work - let me know. I might be able to whip up something in a php file for you to tinker with
    -=Alarion=-
    Protollix - Linux hosting from $3.95/m

  5. #5
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well it sure as hell is confusing
    or maybe its just no sleep getting to me?
    i dunno...

  6. #6
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    damn!
    this works for one level of sub-categories.. what happens when you go a level deeper?
    Last edited by kunal; May 22, 2001 at 11:22.
    i dunno...

  7. #7
    SitePoint Zealot
    Join Date
    May 2000
    Posts
    150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just wondering.. how are you going to grab all categories and subcategories (all levels) in some order (alphabetic/user defined)? Recursion?

    For example, the Add a Link page, will probably need a list of all categories and subcategories, in proper order... I don't know if it will be possible to do that with this current database design.

    ex:
    Main1
    ----------> Sub1
    ----------> Sub2
    ----------> Sub2.Sub1
    ----------> Sub2.Sub1.Sub1
    Main2
    ----------> Sub1

    Arpith

  8. #8
    SitePoint Zealot Alarion's Avatar
    Join Date
    May 2001
    Location
    Virginia
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm.. well I am trying to figure out which table design would be more efficient - the "all in one" or the "split in two" one.

    lets try going with the two tables for this for now:
    Code:
    create table catagory(catid int(8) not null primary key auto_increment, catname varchar(50), catparent_id int(8) default 0);
    create table links(linksid int(10) not null primary key auto_increment, catid int(8), linkname varchar(50), linkurl varchar(255), linkdesc text);
    that give us our two tables.
    now, I am not going to format this all pretty and what not but it should get the point across

    PHP Code:
    <?php
    echo "<html><head><title>test</title></head>";
    echo 
    "<body bgcolor=white text=black link=red vlink=red alink=red>";
    echo 
    "Welcome to the test page!!<br>";

    $conn mysql_connect("localhost""username""password");
    mysql_select_database("databasename");
    if(!isset(
    $catid)) {
      
    $result mysql_query("select catid, catname from catagory where catparent_id = 0 order by catname");
      if (
    mysql_num_rows($result) > 0) {
        while(list(
    $catnum$cattitle) = mysql_fetch_row($result)) {
          echo 
    "<a href=\"$PHPSELF?catid=$catnum\">$cattitle</a><br>";
        }
      } else { echo 
    "no catagories"; }
    } else {
      
    $result mysql_query("select catid, catname from catagory where catparent_id = $catid order by catname");
      if(
    mysql_num_rows($result) > 0) {
        while(list(
    $catnum$cattitle) = mysql_fetch_row($result)) {
          echo 
    "<a href=\"$PHPSELF?catid=$catnum\">$cattitle</a></br>";
        }
      } else { echo 
    "no catagories"; }
      
    $result "select linkname, linkurl, linkdesc from links where catid = $catid";
      if(
    mysql_num_rows($result) > 0) {
        while(list(
    $linktitle$link$linktext) = mysql_fetch_row($result)) {
          echo 
    "<a href=\"$link\">$linktitle</a> - $linktext<br>";
        }
      }
    }
    echo 
    "</body></html>";
    ?>
    i have a test page up with this exact code at http://www.databound-software.com/catagory_test.php

    -=Alarion=-
    Protollix - Linux hosting from $3.95/m

  9. #9
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well.. this code will work for upto, 1 level after the main level... what happens if you have 10 levels under one another? how do you identify what goes where?? I think i have a solution not sure though..
    i dunno...

  10. #10
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    btw.. ur url gave a internal server error
    i dunno...

  11. #11
    SitePoint Zealot Alarion's Avatar
    Join Date
    May 2001
    Location
    Virginia
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bah, register.com is a bunch of incompetent asses. They can't seem to keep their friggin DNS updated correctly

    try http://databound-software.com/catagory_test.php
    -=Alarion=-
    Protollix - Linux hosting from $3.95/m

  12. #12
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Alarion
    bah, register.com is a bunch of incompetent asses. They can't seem to keep their friggin DNS updated correctly

    try http://databound-software.com/catagory_test.php
    hehe

    well see.. your code looks fine.. but what if i have a category below science? say, Chemistry? and below chemistry I had, Organic Chemistry, and then further down I had, Ethers.. blah blah.. how would that work? would it work?
    i dunno...

  13. #13
    SitePoint Zealot Alarion's Avatar
    Join Date
    May 2001
    Location
    Virginia
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    umm.. it should work fine..

    notice there is a biology catagory under science, and under biology are two "dummy" catagories
    -=Alarion=-
    Protollix - Linux hosting from $3.95/m

  14. #14
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmmmm....... loooks deeper
    i dunno...

  15. #15
    SitePoint Zealot Alarion's Avatar
    Join Date
    May 2001
    Location
    Virginia
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe

    So you see, it seems to work fine so far.

    I am not quite sure how you would pickup the relations all the way down for listing them in a listbox:

    ie.
    science
    science:biology
    science:biology:blah
    science:biology:blah2
    science:chemistry
    science:chemistry:blah


    etc etc

    recursion might work, but that is a pain. I would be interested in an algorithm to do that (efficiently)
    -=Alarion=-
    Protollix - Linux hosting from $3.95/m

  16. #16
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wooho.. works man
    thanx
    i dunno...

  17. #17
    SitePoint Zealot Alarion's Avatar
    Join Date
    May 2001
    Location
    Virginia
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    glad I could help!
    -=Alarion=-
    Protollix - Linux hosting from $3.95/m

  18. #18
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well.. you could use the a drop down menu.. and make a the values like this,

    12.2

    where
    12 --> main category
    2 --> current category..

    and then explode it during storage.. something like that way Vbull does it..

    might work..

    *me goes to back to coding*
    i dunno...

  19. #19
    SitePoint Zealot
    Join Date
    May 2000
    Posts
    150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd use another column: (sort_order int) which will be updated everytime a category/subcategory is inserted/deleted.

    science 1
    science:biology 2
    science:biology:blah 3
    science:biology:blah2 4
    science:chemistry 5
    science:chemistry:blah 6

    Then, to select all categories, SELECT * --- ORDER BY sort_order ASC

    Later, if you decide to add science:biology:blah3, you'll give it sort_oder = 5 and move the rest up by one.

    Arpith

  20. #20
    SitePoint Zealot Alarion's Avatar
    Join Date
    May 2001
    Location
    Virginia
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm, good idea Arpith
    -=Alarion=-
    Protollix - Linux hosting from $3.95/m


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
  •