Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP/MySQL Question

  • 04-01-2005 12:58PM
    #1
    Registered Users, Registered Users 2 Posts: 20


    Hi,

    I'm working on a simple proprietary shopping basket system written in PHP with a MySQL back end. My question is: what is the best way to implement subcategories?

    At the moment, I have a database of products which all get listed on the index page (paginated) but I want to organise them into categories and subcategories of varying depths. The index page should list all top-level categories. When the user clicks on one of these, the index page displays the subcategories (if any) or else all the products in that category. And so on.

    Can anyone point me in the right direction on how to implement this? What database fields should I add to the products DB?

    A model of what I want would be Meadows and Byrne.

    I hope this is clear. Can anyone help?

    Thanks,
    Bill.


Comments

  • Registered Users, Registered Users 2 Posts: 7,742 ✭✭✭mneylon


    Have you looked at how OSCommerce handles it?


  • Registered Users, Registered Users 2 Posts: 20 bos


    blacknight wrote:
    Have you looked at how OSCommerce handles it?
    No, but I will now. Does anybody know of any tutorials/basic implementations that I could take a look at?


  • Registered Users, Registered Users 2 Posts: 7,742 ✭✭✭mneylon


    I'd always recommend having a look at Hotscripts.com - there's a lot of tutorials and scripts over there.


  • Registered Users, Registered Users 2 Posts: 1,562 ✭✭✭Snaga




  • Registered Users, Registered Users 2 Posts: 912 ✭✭✭chakotha


    I haven't yet had to go to subcategories but if you have the tables products, categories and products_categories could you add also a categories_categories table?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,452 ✭✭✭tomED


    It depends on how complex you want your overall system to be. The simplest form I ever used is like this:

    A categories table, with a field called "SubOf" - every category, including subcategoires are stored in this table, the SubOf filed will refer to the uppermost categoryID that a category belongs to.

    Example

    [HTML]ID1. Category 1
    > ID2. Sub1 (Subof = ID1)
    > ID3. Sub2 (Subof = ID1)
    > ID4. Subof2-1 (SubOf = ID3)

    Etc....[/HTML]

    Hope that's not confusing.

    You can always add another table that stores the ID's of each category and the category they are a subof, but that just seems like too much work coding wise! :)


Advertisement