SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: category help

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    category help

    Hi,

    I need to add this type of system to my script.

    Home > $category1 > $category2 > $threadID

    So the parentid in $category2 = $category1 and the the formid in $threadID = $category2 and so on.

    Can anyone give me an example of how this works?

  2. #2
    pie??? PIE!!!! rsdl's Avatar
    Join Date
    May 2001
    Location
    Vancouver, BC Canada
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    make three seperate tables.
    category1, category2 and threads

    category1 would contain a unique id and name and other things you might want to add to it.
    category2 containts a uniqueid, category1id, name...etc
    thread would contain a uniqueid, category2id, name...etc.

    then to call and display it, just query the thread, then grab the category2 id and name from the thread query, and then grab the category1 id and name from the category2 query.

    another way is to use the JOIN parameter in mysql., where instead of having to do three seperate queries, you can do one query. and the thread table would contain a unique id, cat1 id, and cat2 id.
    e.g.
    PHP Code:
    $sql = ("select * from thread, category1, category2 WHERE thread.category1=category2.id AND category2.category1=category1.id ")
      or die(
    mysql_error()); 
    i'm just typing this at the top of my head so it might be wrong :P

  3. #3
    SitePoint Guru
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I should have explained myself better, excuse me for not doing that.

    Say I have 3 categories and I click on Category1 it would display

    Home > Category1

    Now, there category2 is inside Cateogry1, so it will display after I click Category2 link.

    Home > Category1 > Category2

    And finally getting the news thread name.

    Home > Category1 > Category2 > threadname


    Somewhat like sitepoints system.
    SitePoint Community Forums / Program Your Site / PHP / category help

    I started to write somme code, but I lost my way for the thread name.
    PHP Code:
    function convert_id_to_cat($el){
    $tmp_query mysql_query("select cattitle from forum_category where fid='$el'");
    $tmp_data mysql_fetch_array($tmp_query);
    return 
    $tmp_data[cattitle];
    }
    function 
    make_location($el){
    $path_array[] = "<font face='arial' size='2' color='#3333CC'> > <b> ".convert_id_to_cat($el)."</b> </font>";
    $this_category $el$parents_left true;
    while(
    $parents_left){
    $tmp_query mysql_query("select parentid from forum_category where fid='$this_category'");
    $tmp_data mysql_fetch_array($tmp_query);
    if(
    $tmp_data[parent_id]>0) {
    $path_array[] = "<font face='arial' size='2' color='#3333CC'> > <a href="cat.php?fid=".$tmp_data[parentid].""><b><font color='#3333CC'>".convert_id_to_cat($tmp_data[parent_id])."</font></b></a></font>";
    $this_category $tmp_data[parentid];
    }
    else 
    $parents_left false;
    }
    $path_array[] = "<font size='4' face='arial'><b>$thecatname</b></font><font face='arial' size='2'><a href="$homepage"><b><font color='#3333CC'>Index</font></b></a></font>";
    $correct_order = @array_reverse($path_array);
    $cat_location = @implode(""$correct_order);
    return 
    $cat_location;
    }
    echo 
    "<table width='750' align='center' border='0' bgcolor='#E7EBFE' cellspacing='0' cellpadding='5'><tr>";
    $cat_id2 $fid;
    $you_are_here make_location($fid);
    echo 
    "<td><font size='2' face='arial'>".$you_are_here."</font></td></tr></table>"

  4. #4
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe try a search here at sitepoint ? This has been discussed before 8)

    As for script, I've yet to implement something like this 8(

  5. #5
    SitePoint Guru
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dr Livingston,

    I tried to do a search but had no luck, maybe im not using the right search word. any ideas?

  6. #6
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "Breadcrumbs" is the word you're looking for. There's quite a few discussions on the topic that you should find useful.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  7. #7
    SitePoint Guru
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's cool, I found a solution with my code. Thanks guys.

  8. #8
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You couldn't post it here for all to see and use ? LoL...

  9. #9
    SitePoint Guru
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    You couldn't post it here for all to see and use ? LoL...
    Sure, it's the same as above, but I added the extra code at the bottom to pick up the thread name.
    PHP Code:

    function convert_id_to_cat($el){
    $tmp_query mysql_query("select cattitle from forum_category where fid='$el'");
    $tmp_data mysql_fetch_array($tmp_query);
    return 
    $tmp_data[cattitle];
    }
    function 
    make_location($el){
    $path_array[] = " > <a href="cat.php?fid=$el"><b>".convert_id_to_cat($el)."</b></a>";
    $this_category $el$parents_left true;
    while(
    $parents_left){
    $tmp_query mysql_query("select parentid from forum_category where fid='$this_category'");
    $tmp_data mysql_fetch_array($tmp_query);
    if(
    $tmp_data[parentid]>0) {
    $path_array[] = " > <a href="cat.php?fid=".$tmp_data[parentid].""><b>".convert_id_to_cat($tmp_data[parentid])."</b></a>";
    $this_category $tmp_data[parentid];
    }
    else 
    $parents_left false;
    }
    $path_array[] = "<a href="$homepage"><b>Index</b></a>";
    $correct_order = @array_reverse($path_array);
    $cat_location = @implode(""$correct_order);
    return 
    $cat_location;
    }
    echo 
    "<table width='750' align='center' border='0' bgcolor='#E7EBFE' cellspacing='0' cellpadding='5'><tr>";
    $you_are_here make_location($fid);
    echo 
    "<td><font size='2' face='arial' color='#3333CC'>".$you_are_here."";
     
    // ==== START: NEW CODE ====
    $sql mysql_fetch_array(mysql_query("SELECT title FROM forum_threads WHERE forumid='$fid'"));
    $title $sql["title"];
    if(
    $threadid==""){ $threadtitle"";} else { $threadtitle " > $title";}
    // ==== END: NEW CODE ====

    echo "$threadtitle</font></td></tr></table>"


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
  •