SQL Recipes
A FREE cookbook for SQL queries and examples
Register FAQ Search Today's Posts Mark Forums Read

SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it.

Go Back   SQL Recipes a FREE cookbook of SQL queries and examples > SQL queries and examples > SQL - Questions and Answers

Reply
 
LinkBack Thread Tools Search this Thread
  #1 (permalink)  
Old 07-21-2007, 09:25 AM
Steve2106
 
Posts: n/a
Default ANY dialect question:

Display from tables


Hi 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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

ANSWER(S):

  #2 (permalink)  
Old 07-21-2007, 04:19 PM
Dimitar
 
Posts: n/a
Default ANY answer. Re: Display from tables

Hi Steve,

One approach would be to use a cursor and for each row if the element has not changed append the responsible name to already seen names for that element.

Only this came to mind. Today is not my day.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-23-2007, 10:40 PM
herschwolf herschwolf is offline
Junior Member
 
Join Date: Jul 2007
Posts: 2
herschwolf is on a distinguished road
Default ANY answer. Re: Display from tables

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 02:19 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
Copyright (c) 2006-2008 SQL Recipes

1 2 3 4 5 6 7 8