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

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

 
0
  #21
Nov 22nd, 2008
OK .. so this is the last part of this ( and I bet you thought you were done with me didn't you? ).

If I wanted to modify the SQL statement you gave me for an update form in which I wanted to show the data just for that user (based in the usr_id passed in the URL string) and for that user, I need to show all of the airports and services available but with the users selections for airports and services checked and the others not?

I have been trying it with multiple recordsets but I am thinking there is a more efficient way?

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
  #22
Nov 22nd, 2008
not quite sure what you are meaning, show me what you want your result set to be and what your current query is
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
  #23
Nov 22nd, 2008
Well, I have attached an image of what I need the layout to be and how it shows ALL of the airports and all three services for each. It also then shows the airports that are selected with their respective services by means of a checkbox.

At this point, while I know I need a more flexible query, I am basically using three separate querys to make this work so far. The problem with it is that all the airports and services get displayed OK ... but they are all checked.

First Query to get the user data:

  1. SELECT *
  2. FROM users
  3. WHERE usr_id = Paramusr_id

Then I am using two queries to get all of the airports and all of the services. The reason I am going this is that I am building a repeat region for the airports, and a nested repeat region for the services is each row that displays the airport current record (see attached image).

  1. SELECT *
  2. FROM airport

  1. SELECT *
  2. FROM service

Then I am getting the records from the userairportservices table where the usr_id_usr matches the usr_id passed in the URL string

  1. SELECT *
  2. FROM userairportservices
  3. WHERE userairportservices.usr_id_users = usr_id

I suspect I need to do a JOIN on these. As far as the layout goes, I am not necessarily stuck on having to do the nested repeat so if the query combines the data properly that I can do a single repeat region and then put the service select boxes in a row with the airport name, code and select box, that will work as well.

Thanks

Dave
Attached Thumbnails
update_users.png  
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
  #24
Nov 23rd, 2008
OK . so here is the beginning of a revised query:

  1. SELECT u.usr_id AS ID, u.usr_fname AS FIRSTNAME, u.usr_lname AS LASTNAME, uas.airport_id_airport AS AIRPORTID, uas.service_id_service AS SERVICEID FROM users u INNER JOIN userairportservices uas ON uas.usr_id_users = u.usr_id

This pulls up the results shown in the attached image. What I need to do now is combine this query somehow with another that selects all of the airports, all of the services -> airports (services for each airport), which would show the user id, the airport id, a 1 or 0 for the airport checked or unchecked, the services for that airport and a 1 or 0 for selected or unselected checkbox.

I thought I was getting the hang of this, and I suppose to a certain degree I am but either I am over-complicating again or this IS complicated. Not sure which. ;-)

Dave
Attached Thumbnails
Picture 7.png  
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
  #25
Nov 23rd, 2008
Wondering why this does not work?

  1. SELECT u.usr_id, a.airport_name, a.airport_id, s.service_id, uas.service_id_service as chosen FROM airport a INNER JOIN service s INNER JOIN users u USING (usr_id) LEFT JOIN userairportservices uas USING (airport_id_airport, service_id_service) ORDER BY u.usr_id, a.airport_name, s.service

Throws the error shown in the attached image. Grrrr!!!!

Dave
Attached Thumbnails
Picture 8.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
  #26
Nov 23rd, 2008
you need to specify inner join on (columnname)
maybe i just don't get it, lol but i cannot understand what you are trying to do here
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
  #27
Nov 23rd, 2008
OK .. I am sure I am not explaining this clearly ??

I need to dynamically list all the airport names and their codes plus a checkbox (which needs to be checked if the user has access to the airport) as well as, in the same row, all the services with a checkbox for each, that are checked or unchecked. depending on whether the database shows the user as having access to the service at this particular airport. Sort of what you gave me before but I need to show all the airports > services, not just the ones that the user has access to. This is because this is part of an update form where the admin may be adding or removing access to an airport that was not previously selected.

I might be able to use PHP and the previous query you gave me to get what I need but I am thinking that there is a way to do this completely in a query. This would be quicker and more efficient I would think.

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
  #28
Nov 23rd, 2008
i don't have a mysql database in front of me right now, but trying changing that statement i gave you, to a right join instead of inner
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
  #29
Nov 23rd, 2008
Looks to be the same results.

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
  #30
Nov 23rd, 2008
reverse the statement and use a left

  1. SELECT ....
  2. FROM airports
  3. LEFT JOIN user_airport_services
  4. on ....
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