Pulling related data from relational dB re: thread: Problems with a many-to-many inse

Thread Solved

Join Date: Nov 2008
Posts: 73
Reputation: filch is an unknown quantity at this point 
Solved Threads: 1
filch filch is offline Offline
Junior Poster in Training

Pulling related data from relational dB re: thread: Problems with a many-to-many inse

 
0
  #1
Nov 19th, 2008
OK, now that I managed to insert data properly into a relational database using a linking table, I am now faced with pulling the data properly out of the database, a displaying it so it makes sense. As a recap, I have inserted user data into a data base that included the usual name address, phone, email etc, as well as the fact that they have access to various airports and at each airport, access to one to three services, which are the same for every airport. ( see my previous thread called Problems with a many-to-many insert for more details ).

I have written the following SQL statement, which does indeed get all of the airports and services that a particular user has access to but I need to get them out in a related manner. For example, the user has access to airport YVR and has access to services Jet and Ground at this airport. He also has access to airport YYZ and at this airport, he has access to services Jet Ground and Glycol. Here is the SQL:

  1. SELECT airport.airport, service.service, userairportservices.usr_id_users
  2. FROM airport, service, userairportservices
  3. WHERE userairportservices.usr_id_users = usr_id AND service.service_id = userairportservices.service_id_service AND airport.airport_id = userairportservices.airport_id_airport

And here is the info it pulls out: [ attached screen grab ]

So, I need to figure out a way to put this back into the page for display [ see second image for example of page ]. Obviously, it is being displayed in two forms: one as a non-editable details display and two, as an editable form for updating the record. So th image merely gives you an example of how I want to display the relationship between airport and services.

As always, I appreciate any insight and help.

Dave
Attached Thumbnails
Picture 1.png   test_insert_form.02.png  
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many inse

 
0
  #2
Nov 19th, 2008
lol oh filch

this is where the dynamic piece would have helped on the saving

i would suggest to possibly alphabetize them, that is unless they are in order by id

to your query add this


  1. ORDER airport.airport asc, service.service asc
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 73
Reputation: filch is an unknown quantity at this point 
Solved Threads: 1
filch filch is offline Offline
Junior Poster in Training

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many

 
0
  #3
Nov 19th, 2008
Actually, the insert form is being built dynamically. I did manage to get that done. This is a separate page and is not a form. This is a page that simply displays the users details. I am just trying to now display it in a grid, similar to the grid I used to insert it.

I am using the ORDERBY command first by airport and then by service, as you suggest but I want to only output the airport name once but if you look at the output I am getting, you see that an airport can have up to three records per user, depending on how many of the three available services the user has access to.

I am looking for a method to have the data repeat like in a repeat region. But only one row per airport but inside that row, a nested repeat that outputs all the services for that airport. And then moves on to the next airport.

Dave
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many inse

 
0
  #4
Nov 19th, 2008
why not do the similar thing as before

loop through the results
when the airportcode changes that means you are in a new group

if in same group, loop through the services and check the appropriate box

i'm not really following the part you are having trouble with, unles you are meaning you want rows to columns? meaning one single row per airport with columns of services
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 73
Reputation: filch is an unknown quantity at this point 
Solved Threads: 1
filch filch is offline Offline
Junior Poster in Training

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many

 
0
  #5
Nov 19th, 2008
Yeah I want there to be one row per airport and then, inside of that row, I want to list the related services, either as columns or as rows.

I have attached what my current SQL query is giving me. So now I just need a way to put it on the page.

Dave
Last edited by filch; Nov 19th, 2008 at 6:16 pm.
Attached Thumbnails
Picture 4.png  
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many inse

 
0
  #6
Nov 19th, 2008
Yeah I want there to be one row per airport and then, inside of that row, I want to list the related services, either as columns or as rows.
you are meaning sql or php?
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 73
Reputation: filch is an unknown quantity at this point 
Solved Threads: 1
filch filch is offline Offline
Junior Poster in Training

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many

 
0
  #7
Nov 19th, 2008
Ahh yes .. I mean in PHP. I guess, as I have an SQL query that gives me what I want, this question would not be appropriate here? I think I was wondering if there was a way to write an SQL query that give me the one airport as well as the one to three associated services back as one record rather than two or three.

D
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many inse

 
0
  #8
Nov 19th, 2008
just to be sure this is what you are meaning, here's a similar post

http://www.daniweb.com/forums/post735371-9.html

is this what you want?
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 73
Reputation: filch is an unknown quantity at this point 
Solved Threads: 1
filch filch is offline Offline
Junior Poster in Training

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many

 
0
  #9
Nov 19th, 2008
To be truthful I am not sure. I understand some of that but not enough to know if it would work with my situation. It seems like it would but I am not sure.

Dave
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many inse

 
0
  #10
Nov 19th, 2008
will you post the structure and i get you a query?
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC