![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
return results from 2 tables with a one to many relationshipI am trying to print a table where the first set of columns are a single row.
The last column will display 2 results separated by a <br>.. Example chapter, address, city, st, officer1<br>officer2<br>officer3 I have 2 tables one that contains the officers and on the chapter names and addresses - linked together by chapter number $num I have tried several foreach's and do while's without any luck. The results I get are a row for each officer and the first 4 columns are duplicated for each officer. My code below PHP Code:
Any help would be much appreciated.. Thanks Last edited by LuciWiz : 16-Sep-2007 at 07:03.
Reason: Please insert your Php code between [php] & [/php] tags
|
|
#2
|
||||
|
||||
Re: return results from 2 tables with a one to many relationshipTo make that more clear, can you post an example of the results you get?
__________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#3
|
|||
|
|||
Re: return results from 2 tables with a one to many relationshipThe results I get are:
chapter1, address, city, state, officer1 chapter1, address, city, state, officer2 chapter1, address, city, state, officer3 chapter2, address, city, state, officer1 chapter2, address, city, state, officer2 etc.... what i want is: Chapter1, address, city, state, officer1<br>officer2<br>officer3 Chapter2, address, city, state, officer1<br>officer2<br>officer3 etc.. |
|
#4
|
||||
|
||||
Re: return results from 2 tables with a one to many relationshipYou can do this with two queries: (there might be nifty ways to do something different within the PHP api, but I don't have time to get into that right now)
1. gather the chapters, and locations (which you mainly have now), but group by the chapter, for the goal is to get each chapter/address to appear only once in the results. 2. then another query to get all the officers, based on the chapter. It appears that 'num' is some sort of referencing id? If so, then use this within the query too. There problem is (well, it's not actually a problem, but just how the database gives the information) that the information from table 'a' is being 'paired' to information from table 'b'. A grouping clause will not help here either, because the officer names are unique, and there will still be three rows per chapter (assuming that there are three matches in table 'b' for each table 'a' entry) So that working with the data will look something like this pseudo-code: Code:
__________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#5
|
|||
|
|||
Re: return results from 2 tables with a one to many relationshipThank You, I thought I had tried that, but evidently my 2nd query was outside the first query. Now that I have it inside, it works like a champ..
Thanks, |
Recent GIDBlog
Toyota - 2008 August Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| yet another linked list program | aijazbaig1 | C Programming Language | 15 | 11-Sep-2007 13:18 |
| need help with a console menu system | BullBuchanan | C++ Forum | 6 | 20-Aug-2006 14:46 |
| Reading non ASCII with read() | Atomical | C Programming Language | 8 | 13-Sep-2005 14:30 |
| Problem with one variable | bretter | C++ Forum | 1 | 16-May-2005 07:20 |
| C++ file I/O | CronoX | C++ Forum | 36 | 09-Mar-2004 17:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The