>I hope somebody may of come across this sort of problem before dealing with
>counting total records in subcategories.
>
>I have two tables sslinks which contains links (URL) information and
>sslinkcats which contains category information.
>
>The category table "sslinkcats" has a field called "lcat_id" (which is an
>autonumber) and also "lcat_cat" which is the "lcat_id" value of the parent
>category. For example cricket would be under sport and the "lcat_cat" of
>cricket would be "lcat_id" of sport.
>
>The problem is that the below statement will only count the number of links
>in each particular category.
>
>$sql = "SELECT sslinkcats.lcat_id, COUNT(*) AS NumLinks
>  FROM sslinks, sslinkcats
>  WHERE link_cat = sslinkcats.lcat_id
>  AND link_validated = 'yes'
>  GROUP BY link_cat";
>
>I want to display the total amount of links under the category sport to
>include all subcategories like football,cricket,cricket rugby. Also if
>cricket had subcategories, then I would these counted too.
>
>I am sure the answer is looking at me but I just can't see it. Therefore any
>pointers or assistance would be very welcome.
>
>(ps. If you have read this message before, apologies but I was informed that
>this is the correct category for this type of question. Sorry)

Sir, since you have chosen the tree structure approach rather than 
the relational database approach, I'd recommend reading 'SQL for 
Smarties' by Joe Celko. There are two chapters on dealing with tree 
structures in SQL.

Bob Hall

Know thyself? Absurd direction!
Bubbles bear no introspection.     -Khushhal Khan Khatak

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to