dev07 Posted July 13, 2011 Share Posted July 13, 2011 Hello everyone, I am trying to create view like tree for last few days. But, i failed to do so. Let me explain my aim. 1) I have table of user-offers. Its structure is given below. ID(primary_key) --- ListerId----ListerItemId----InterestedUserId----InterestedUserItemId----Accepted 1 --------------------- 20 ------ 25 ----------- 41 ----------------- 45 -----------------0 2---------------------- 20 ------- 25 ----------- 44 ------------------ 50 -------------------0 3--------------------- 41 ------- 45 ------------- 51 ------------------ 52 -------------------0 4---------------------- 51 --------- 52 ------------ 60 ----------------- 61 ---------------------0 5----------------------- 60 --------- 61 ------------ 70 ------------------ 71 --------------------0 6----------------------- 41 --------- 45 ------------ 70 ------------------ 71 --------------------0 2) Suppose, i am lister and my id is 20, my item id is 25. User 41 has offered me for his item 45. User 41 got offer for the same item 45 (user 41 has offered for this product to me) from other user 51 for his item 52. Also the user 41 got offer for the item 45 from user 70 for user 70's item 71. 3) user 51 got offer for his product 52 from user 60. user 60 offered him item 61. 4) user 60 got offer for his product 61 from user 70. user 70 offered him item 71. 5) Now , i (user id 20) want to check who has made offer to me for my item 25. Here user 41 made offer for 45 and user 44 made offer for item 50. 6) I also want to check who has made offer to user 41 for his item 45. Here user 51 has made offer for 52. 7) And the process continues. Can anyone help me on this? I need help badly at this moment. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/241872-how-to-create-a-tree-view-of-a-table-information/ Share on other sites More sharing options...
freelance84 Posted July 13, 2011 Share Posted July 13, 2011 Soo... what's the problem... what info are you requiring from the table and when, and what is stopping you at the moment? Link to comment https://forums.phpfreaks.com/topic/241872-how-to-create-a-tree-view-of-a-table-information/#findComment-1242137 Share on other sites More sharing options...
dev07 Posted July 13, 2011 Author Share Posted July 13, 2011 Soo... what's the problem... what info are you requiring from the table and when, and what is stopping you at the moment? Hi Devotee, My target is: 1) I want to check who all offered me [in the give example: my user id is 20] for my item id 25. I know, using a while it is possible. 2) I also want to have a list of those users(listers) who offered the previous users(previous users= who has made offers to me). This is where i am stuck. Let me explain (considering the above example): ListerId= (userid , unique) who has listed an item and expecting offer from other lister. ListerItemId= (itemid, unique) lister has listed this item and expecting offer from other lister for this item. InterestedUserId= (userid , unique) who has made an offer to the lister. InterestedUserItemId=(itemid, unique) interested user has offered this item to the lister. Lister can also make an offer to other lister. My user id is 20 and my item id is 25. I listed it and user 41 offered me his item 45. At the same time, another user 44 offered me his item 50. Using while loop i can see this result. I also want to see who has offered user 41 for his product 45. And, who has offered user 44 for his product 50. Here, user 51 made an offer for his item 52 to user 41. Similarly, want to check who has offered user 51 for his product 52. This way the tree continues. I want to see this whole tree at the first by clicking on user 41. This is where i am stuck. I don't want to click on each user to see his offer. I want to display all these offer automatically once i click on user 41. The above mentioned example is an easy example. I have attached an picture. Please have a look on it. It can be a bit complex. Can you please help me on this? Thanks in advance. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/241872-how-to-create-a-tree-view-of-a-table-information/#findComment-1242145 Share on other sites More sharing options...
freelance84 Posted July 13, 2011 Share Posted July 13, 2011 Ok, struggling to understand what you're trying to say here. Is this correct (assuming userID 20 is running the script): 1. See what the latest offer is for Item25, and by who. 2. See all previous offers on Item25 and by who in date order. Link to comment https://forums.phpfreaks.com/topic/241872-how-to-create-a-tree-view-of-a-table-information/#findComment-1242151 Share on other sites More sharing options...
dev07 Posted July 13, 2011 Author Share Posted July 13, 2011 Ok, struggling to understand what you're trying to say here. Is this correct (assuming userID 20 is running the script): 1. See what the latest offer is for Item25, and by who. 2. See all previous offers on Item25 and by who in date order. Hi Devotee, No, its not like that. Assume userID 20 is running the script. 1) See all the offer is for Item25, and by who. Eg. ==>considering the above example, i must get the result of item45 and item50. 2) Also, see all offers made on item45 and item50. ==> considering the above example, i must get the result of item52 (for item45). No item has been offered for item50. 3) See all offers made on item52. ==> considering the above example, i must get the result of item61 (for item52). 4) Thus the process continues. 5) I want to see this whole tree once i click on my offer (for item 25). Link to comment https://forums.phpfreaks.com/topic/241872-how-to-create-a-tree-view-of-a-table-information/#findComment-1242162 Share on other sites More sharing options...
freelance84 Posted July 13, 2011 Share Posted July 13, 2011 ID(primary_key) --- ListerId----ListerItemId----InterestedUserItemId----InterestedUserItemId----Accepted 1 --------------------- 20 ------ 25 ----------- 41 ----------------- 45 -----------------0 2---------------------- 20 ------- 25 ----------- 44 ------------------ 50 -------------------0 3--------------------- 41 ------- 45 ------------- 51 ------------------ 52 -------------------0 4---------------------- 51 --------- 52 ------------ 60 ----------------- 61 ---------------------0 5----------------------- 60 --------- 61 ------------ 70 ------------------ 71 --------------------0 6----------------------- 41 --------- 45 ------------ 70 ------------------ 71 --------------------0 1) See all the offer is for Item25, and by who. Eg. ==>considering the above example, i must get the result of item45 and item50. Just run a query which will either: 1. Get InterestedUserItemId and InterestedUserItemId from the table WHERE ListerId = 20 or 2. Get InterestedUserItemId and InterestedUserItemId from the table WHERE ListerId = 20 AND ListerItemId = 25 ________________________________________________________________________________________ 2) Also, see all offers made on item45 and item50. ==> considering the above example, i must get the result of item52 (for item45). No item has been offered for item50. Run a query which will: Get InterestedUserItemId and InterestedUserItemId from the table WHERE ListerItemId = 20 _______________________________________________________________________________________ .... thus the process continues. If you need any more help than that it would suggest you dont know how to write the queries which would indicate you need a freelancer or, a good book and time to learn. Link to comment https://forums.phpfreaks.com/topic/241872-how-to-create-a-tree-view-of-a-table-information/#findComment-1242205 Share on other sites More sharing options...
dev07 Posted July 13, 2011 Author Share Posted July 13, 2011 Hello Devotee, Thanks for your quick reply. But its not so easy as you are thinking. I know i can generate the first stage [first point] easily using a while loop. But, the main problem will be on second stage as i dont have the child node initially. By clicking on the child node,i will get their id and thus i have to proceed as suggested by you. But, i want to have the child node first from the first stage. That is the main problem Link to comment https://forums.phpfreaks.com/topic/241872-how-to-create-a-tree-view-of-a-table-information/#findComment-1242219 Share on other sites More sharing options...
freelance84 Posted July 13, 2011 Share Posted July 13, 2011 Hey, sorry that second query should have been WHERE ListerItemId = 45 Hello Devotee, Thanks for your quick reply. But its not so easy as you are thinking. I know i can generate the first stage [first point] easily using a while loop. But, the main problem will be on second stage as i dont have the child node initially. By clicking on the child node,i will get their id and thus i have to proceed as suggested by you. But, i want to have the child node first from the first stage. That is the main problem ID(primary_key) --- ListerId----ListerItemId----InterestedUserItemId----InterestedUserItemId----Accepted 1 --------------------- 20 ------ 25 ----------- 41 ----------------- 45 -----------------0 2---------------------- 20 ------- 25 ----------- 44 ------------------ 50 -------------------0 3--------------------- 41 ------- 45 ------------- 51 ------------------ 52 -------------------0 4---------------------- 51 --------- 52 ------------ 60 ----------------- 61 ---------------------0 5----------------------- 60 --------- 61 ------------ 70 ------------------ 71 --------------------0 6----------------------- 41 --------- 45 ------------ 70 ------------------ 71 --------------------0 Sure you do, its in the previous query: 1. The ID of the logged in user is 20 => set into session. 2. Get the ListerItemId from the table where ListerId = sessionID 3. Foreach of the results returned from step 2 run another loop which gets the InterestedUserItemId and InterestedUserItemId 4. Foreach of the results from step 3, get the InterestedUserItemId InterestedUserItemId WHERE ListerItemId = one of the results from the previous query. Link to comment https://forums.phpfreaks.com/topic/241872-how-to-create-a-tree-view-of-a-table-information/#findComment-1242227 Share on other sites More sharing options...
dev07 Posted July 14, 2011 Author Share Posted July 14, 2011 3. Foreach of the results returned from step 2 run another loop which gets the InterestedUserItemId and InterestedUserItemId 4. Foreach of the results from step 3, get the InterestedUserItemId InterestedUserItemId WHERE ListerItemId = one of the results from the previous query. Hi Devotee, Yes, I have to run this "Foreach" loop each and every time to display the InterestedUserId and the InterestedUserItemId of previous query. But, as a developer, i will be having no idea of the depth of the table at first to get the InterestedUserItemId of previous query. Thats why, i have to make it dynamically so that no matter what is the depth of the tree, i will display all the InterestedUserId and InterestedUserItemId. This is where i am stuck. Can you please help me on this? Or can you please write the mysql query for this tree? Link to comment https://forums.phpfreaks.com/topic/241872-how-to-create-a-tree-view-of-a-table-information/#findComment-1242586 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.