Jump to content

[SOLVED] Here is a tricky one... db theory


forumnz

Recommended Posts

Well, lets say that I have 100 auction categories each assigned a number (100,101,102 etc).

 

I have a main category called 100,

a sub category called 101,

and a third level category called 102.

 

So user would have to click 3 times to get to 102 (like Art>Supplies>Brushes).

 

Lets say the user was on .com/browse.php?cat=101 (or Supplies) and I wanted it to show all the next categories ie 102,103,104 etc. How would I have that in a db?

Also, in cat 101 it would display below some auctions (eg closing) from 102,103,104. HOw should I code that in a db?

 

More info. If user click on a third level cat e.g 102, then the url would be .com/browse.php?cat=102.

 

Get what I mean? So in cat 100 we would be able to see other sub cats + other sub cats auctions. Then in next sub cat we would see those sub cat auctions + third level sub cats. Then in the third level we would only see those auctions and not and mroe cats.

 

I know this may be hard (or easy) but please help!

 

Thanks you very much.

Sam.

Link to comment
Share on other sites

Thanks for that. I kind of understand it now. I have used the link from jitesh.

 

The output is this:

-me
- -myselft
- - -again!!
- - - -test1
- - - -test2
- - - - -test3
- - - - - -test4




me
me -myselft
me -myselft -again!!
me -myselft -again!! -test1
me -myselft -again!! -test2
me -myselft -again!! -test2 -test3
me -myselft -again!! -test2 -test3 -test4

 

I can understand how that is working, but lets say the user was in the first cat of 3, how would I display say the 20 auctions from all the subcats that were closing the soonest?

 

Thanks,

Sam.

Link to comment
Share on other sites

Righto,

 

Well, as an example, lets say there is an auction site with many categories and user clicks on Tools then Power Tools then Drills.

 

The user is now in the drills section and we can display all the auctions from drills.

What I want is, lets say the user clicks on Tools and nothing else. The should see the sub categories (i.e Power Tools, Hand Tools) and under them them should see a selection of auctions from all the categories and sub cats within the sub cats.

 

You get it?

 

Tools - Power Tools - Drills

                                - Jigsaw

        - Hand Tools

 

See? So if user click on Tools they will see sub cats Power Tools and Hand Tools. PLus they will see auctions from drills and jigsaw there.

 

Understand?

 

Sam.

 

Link to comment
Share on other sites

Yes getting you.

 

This is so simple

 

Now see below function in nested-categories.php file.

 

function get_cats(&$cats_result , $parent_id = 0 , $level = 1)
    {
            $this->cats = array();
        $this->tmp_cats = array();
            $this->get_cats_($cats_result,$parent_id, $level);
    }

When first time the page will be load then the parent_id will be 0 in this function.

 

Now when user click on any category then pass category id for selected category to parent_id in above function. It will give you tree from that category.

Link to comment
Share on other sites

1) When page load first time the url will be like this

   

    www.site.com/category.php

    // Code to load parent categories

 

 

2) Now each time when click the url will be like this

 

    www.site.com/category.php?category_id=100

    // Pass category id as parent id in function. will give tree from given category id.

 

   

   

 

 

Link to comment
Share on other sites

(1) Parent Level (First Time) : Load all categories which has "parent" 0 in table.

(2) Now for next all time whichever category is clicked will be parent for open all opened sub categories.

    while the categories level 0 ("parent" 0 in table) will be same at their posision.

Link to comment
Share on other sites

First time write a query.

 

Select * from categories where parent = 0;

 

Display all parent level categories

 

Second

 

Continue with Select * from categories where parent = 0;

 

now for selected category write a query.

 

select * from categories where parent = " selected category id ",

 

and access that function with passed the " selected category id " as a parent id.

 

Diplay your contents.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.