| | |
Pulling related data from relational dB re: thread: Problems with a many-to-many inse
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 73
Reputation:
Solved Threads: 1
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:
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
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:
MySQL Syntax (Toggle Plain Text)
SELECT airport.airport, service.service, userairportservices.usr_id_users FROM airport, service, userairportservices 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
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
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
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
MySQL Syntax (Toggle Plain Text)
ORDER airport.airport asc, service.service asc
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Nov 2008
Posts: 73
Reputation:
Solved Threads: 1
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
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
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
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
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
www.houseshark.net
•
•
Join Date: Nov 2008
Posts: 73
Reputation:
Solved Threads: 1
Re: Pulling related data from relational dB re: thread: Problems with a many-to-many
0
#5 Nov 19th, 2008
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
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.
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Nov 2008
Posts: 73
Reputation:
Solved Threads: 1
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
D
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
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?
http://www.daniweb.com/forums/post735371-9.html
is this what you want?
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Nov 2008
Posts: 73
Reputation:
Solved Threads: 1
Re: Pulling related data from relational dB re: thread: Problems with a many-to-many
0
#9 Nov 19th, 2008
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
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
www.houseshark.net
![]() |
Other Threads in the MySQL Forum
- Previous Thread: Which is better? Tons of separate tables with a little data or one big table?
- Next Thread: update in steps? is it possible ?
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api aws bizspark breathalyzer changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization






