| SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it. |
|
|||
Display from tablesHi Guys,
Can you help me please. I have 3 tables. Elements, ResponsiblePeeps, ElementsRespLookup Elements Tabel Layout: ElementID Int, identity ElementDesc Varchar(50) ResponsiblePeeps Table Layout: ResponsiblePeepsId Int, Identity ResponsibleName Varchar(50) ElementsRespLookup Table Layout: ElementID Int ResponsiblePeepsId Int I need to show the ElementDesc field in the first column of a grid and then go to the ElementsRespLookup and get the ResponsiblePeepsId that are linked to the ElementID and then display the ResponsibleName from the ResponsiblePeeps Table in the next column. For each row of element data I have in a table there can be 1 or more responsible persons for that element. In each datarow I need to show the element and all the responsible people in the adjacent cell. IE. +-----------------------------------+----------------------------------+ |.......Element................................|.. ............Responsible...................| +-----------------------------------+----------------------------------+ |Development and execution.............|..........Jason Davis.......................| |................................................. |...........Steve Wilson.....................| |................................................. |...........Jake Smith........................| +-----------------------------------+----------------------------------+ |Logistics......................................|. ..........Andrew Fuller....................| +-----------------------------------+----------------------------------+ How can I do that. I can pull out the responsible people if there is only 1 but I do not know how to put 2 or more in the same cell. I hope that makes sense. Thanks for your help I really appreciate it. Best Regards, Steve. |
|
|||
|
I'm pretty limited in my knowledge of MySQL queries and how they pull data, but my idea would be to use a foreach loop of an array to display your data.
To create your array I would first setup an empty array and then pull all the Element Descriptions first and then run a while statement to extract them and first place it into the array. Then in the same while statement after putting that data into the array run a second statement to pull all the id's and extract those and run them through another while statement that pulls the names associated with the ids (which through each of the passes of the while statement will only contain those id's that are associated with the respective element description. Push those names into the array and close the second while statement and then immediately close the first while statement to loop all those actions. Then you have an array that contains the element description followed by the names associated with it. Run a foreach on the array to grab the data and display in the necessary way you want it. It might be a little more complicated than my writing really suggests, but if you understand PHP it shouldn't be really that difficult just time consuming in testing and getting it all written. Please feel free to email me at mail[at]herschwolf[dot]net if you want some help it as I've done something exactly like this about a month ago. -Nathan |
![]() |
| Thread Tools | Search this Thread |
|
|