Jump to content

Get all details of child with relation of its parents in php mysql


shashib
 Share

Recommended Posts

Cat and sub category Table (cat_tbl) :

id| cat_n | parent_id1 | cat    | 02 | dog    | 03 | tiger  | 24 | lion   | 05 | abc    | 06 | bcd    | 3

Now i have a product table as below (prod_tbl) :

id | pwght | cid | cpid10 | 1.2   | 1   | 011 | 2.4   | 2   | 012 | 3.4   | 2   | 013 | 4.5   | 6   | 3

and user final weight product table is below (userprod_tbl)

id | pwght | cid | cpid | prod_id ( is above prod_tbl primary id )1  | 1.1   | 1   | 0    | 102  | 2.3   | 2   | 0    | 113  | 3.1   | 3   | 2    | 124  | 4.0   | 6   | 3    | 13

**RESULT : ( OUTPUT WHICH I WANT ) IS comparison of prod_tbl with userprod_tbl as below :**

Prod tbl                                   Userprod tblcat 1.2                                    cat          1.1dog 2.4                                    dog -- --    2.3dog 3.4                                    dog tiger -- 3.1dog 4.5                                    dog tiger bcd 4.0

Hence in above result 2.4,3.4,4.5 are belong to Parent 2**But i am getting as below**

Prod tbl           Userprod tblcat 1.2            cat 1.1dog 2.4            dog -- -- 2.3dog 3.4            dog tiger -- 3.1here i am not getting 4.5 value as 4.5 has 6,3 relation from above prod table but its parent of 2

**Below is my query which i have return:**

SELECT pt.pwght , upt.pwght ,ct.cat_n,uct.cat_n,umct.cat_nFROM prod_tbl AS ptLEFT JOIN userprod_tbl AS upt ON (pt.id = upt.prod_id)LEFT JOIN cat_tbl AS ct ON pt.packet_id = ct.idLEFT JOIN cat_tbl AS uct ON upt.packet_id = uct.idLEFT JOIN cat_tbl AS umct ON upt.parent_packet_id = umct.id

Please let me know what is missingThanks

Edited by shashib
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...