PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 23rd, 2004, 09:30 AM
nevillemehta nevillemehta is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: India
Posts: 64 nevillemehta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 44 m 17 sec
Reputation Power: 6
Recursive category problem...

Hello,

Here's the problem...

I have two tables in the DB-:

1. Category Table
Fields: id,name,sub_id
(id and sub_id are releated recursivly)

Eg. of a populated 'category' table!
1,Home,0
2,A,1
3,B,1
4,C,1
5,Avalanche,2
6,Bat,3
7,Carpet,4

2. Links
Fields: name,cat_id,date
(cat_id and id from category are releated)

Eg. of a populated 'links' table!
Link Home,1,2004/12/10
Link Carpet,4,2004/11/10
Link Bat,3,2004/10/10


Now, when i display all the (mainly top level) categories i need a method which would return me the date when the category was last updated! With that i mean the date of the link which was last added in that category (that includes any category under it and so on...).

So when i ask that method for the last updated date for say the 'Home' (topmost level) category from the sample data i have provided it should return me 2004/12/10.


------------------------------------
I have coded this but the problem is that this code is extremely heavy and as the links increase in the database i guess this way will soon give way. Anyway, let me write you my approach...

method returnLastDate(catid)
For all links (order by date desc)
if ( isChild(link[id],catid) )
return link[date]
end method returnLastDate

method isChild(son,dad)
if ( if son is a link in ANY subcat of dad )
return true
else
return false
end method isChild

(isChild is a recursive method which will return you true if son is a link in ANY sub category of dad)


I basically traverse through all the links (in descending order) and for each link i check whether it is a part of any subcategory of the category i need to get the last updated date for!
------------------------------------

Please suggest me an alternative approach as this one is toooo heavy and will eventually break down (it already is as i am getting these timeout errors frequently).

Thanks
Neville

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Recursive category problem...


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