james.sriot
09-27-2008, 09:57 AM
Ok, I have an interesting issue where I want to condense multiple queries being run on one page into one query if possible.
Here is the scenario. This is a manager section to manage links and whether or not someone has access to them or not.
The layout is as follows (on the webpage):
Group 1 Group 2 Group 3
Link 1 x
Link 2 x x
Link 3 x
There are 3 tables being worked with. One table houses the links, another the groups and a linking table in the middle. So that layout is the following:
LINKS LNK GROUPS
id id id
link link_id group
group_id
If the a group can view a link then it is added to the LNK table. So, for example, assuming that the links have an ID of (1,2,and 3) and the groups have the same (1,2,and 3) the linking table would look something like this (with what is checked in the example
LNK
id link_id group_id
1 1 1
2 2 2
3 2 3
4 3 2
With that, here is what I am trying to accomplish. In my script I have to return the LINKS from the links table as well as the GROUPS from the groups table. I have a simple return for this so it displays them going in the correct direction.
What I want to do is for each row returned I want to associate the columns that should be checked by returning a 1 or a 0. I am not sure how to do this because when using the linking table all that will match is what is properly linked. I want to be able to say that there should be at least three returns per row (one for each group) then go to the next row get the link and check 1 .... 2..... 3 and if there is a match in the linking table return a 1 so i can display that on the screen.
This will avoid having to run a loop of queries for each stop on the grid.
Hopefully not too confusing. Any ideas would be appreciated.
Here is the scenario. This is a manager section to manage links and whether or not someone has access to them or not.
The layout is as follows (on the webpage):
Group 1 Group 2 Group 3
Link 1 x
Link 2 x x
Link 3 x
There are 3 tables being worked with. One table houses the links, another the groups and a linking table in the middle. So that layout is the following:
LINKS LNK GROUPS
id id id
link link_id group
group_id
If the a group can view a link then it is added to the LNK table. So, for example, assuming that the links have an ID of (1,2,and 3) and the groups have the same (1,2,and 3) the linking table would look something like this (with what is checked in the example
LNK
id link_id group_id
1 1 1
2 2 2
3 2 3
4 3 2
With that, here is what I am trying to accomplish. In my script I have to return the LINKS from the links table as well as the GROUPS from the groups table. I have a simple return for this so it displays them going in the correct direction.
What I want to do is for each row returned I want to associate the columns that should be checked by returning a 1 or a 0. I am not sure how to do this because when using the linking table all that will match is what is properly linked. I want to be able to say that there should be at least three returns per row (one for each group) then go to the next row get the link and check 1 .... 2..... 3 and if there is a match in the linking table return a 1 so i can display that on the screen.
This will avoid having to run a loop of queries for each stop on the grid.
Hopefully not too confusing. Any ideas would be appreciated.