PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old October 11th, 2002, 09:35 PM
webhappy webhappy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Silicon Valley, CA, USA
Posts: 203 webhappy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Infinite-layers of categorization

Hi,

I'm wondering if there's a way to imlement an infinite amount of layers of categorizations.

For examle, my forums on my site are categorized in forum categories.
Thus, I have a table called forumTopics like this:
int forumId
int forumCategory

And a table called forumCategories
int forumCategory
text forumCategoryName

I'm wondering if there's a way to support an infinite amount of layers of categorization. For simplicity, my child layers do not need to support more than 1 parent.

Thus, it could just be something like this:
1a
2a
3a
4a-1 4a-1
5a-1-1 5a-1-2 5a-1-1

Er... I hope that made sense! Thanks.

Reply With Quote
  #2  
Old October 12th, 2002, 12:01 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Infinite-layers of categorization

Well, here's the way I've always done thing like that...for simplicity, I will only deal with a table with two columns. id and parent_id. Each item in the table will have it's own unique id. Each will have a parent_id that corresponds to another id in the table. Top level items have a parent of 0.

So, when you want to pull all top level items, just pull WHERE parent_id = 0. Then, once an items is clicked and you are looking for subs under it, WHERE parent_id = id_that_was_clicked.


Reply With Quote
  #3  
Old October 13th, 2002, 12:31 AM
webhappy webhappy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Silicon Valley, CA, USA
Posts: 203 webhappy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Infinite-layers of categorization

Ah, thanks...

Hm... Yup, I was thinking of a way to do it with only 2 tables, but this way's pretty good. With only 1 table, min. of 3 fields: int id primary key, int id parent_id, text description

Reply With Quote
  #4  
Old November 6th, 2002, 03:36 AM
webhappy webhappy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Silicon Valley, CA, USA
Posts: 203 webhappy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Infinite-layers of categorization

Is it possible to fetch all parents of a layer without using n mysql calls if it is n layers deep? Can I sort-of hack it, something like:
select * from layers a left join layers b where b.id=a.parentId left join layers c where c.id=b.parentId ?

Reply With Quote
  #5  
Old November 6th, 2002, 10:37 PM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: Infinite-layers of categorization

yes, but only if you know how "deep" the category is. if you know that cat is on 7th level, you can use 7 joins much like you shown.

(u can add another column that holds level, and store it when you add category)

but it wont work any better than when you do it from php. sql server still has to do it 7 times... (it may even work slower?)

Reply With Quote
  #6  
Old November 8th, 2002, 12:03 AM
webhappy webhappy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Silicon Valley, CA, USA
Posts: 203 webhappy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Infinite-layers of categorization

Hm... how big is the overhead to do mysql_query() in PHP?

I always assumed that it is just better to lessen the number of calls PHP needs to do... but I think you're right in that the performance for the mySQL server is no better and could even be worse.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Infinite-layers of categorization


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway