This is a little difficult to explain, so bear with me. Below is a query I'm using to exctract data from a table filled with data about people in various nations (cia_ppl)...
The WHERE clause makes sure it doesn't display places where no people live (POPulation = 0). I joined it to table gw_geog because that's where the full name of each nation is stored.PHP Code:$res = mysql_query ("SELECT * FROM cia_ppl CP
LEFT JOIN gw_geog GG on GG.IDArea = CP.ID_Name
WHERE CP.Pop != 0") or die (mysql_error());
Now I want to join another table that contains my footnotes, and I'm getting confused. First, let me offer some sample rows from the main table, cia_ppl:
The footnotes table - cia_notes - matches cia_ppl via the field ID_Name. It contains three other fields for notes, note codes and category, like this:NAME / POP(ulation) / Age_Ave
aus / 48 million / 25
can / 60 million / 26
usa / 300 million / 28
I would like to display the appropriate footnote codes (cia_notes.Cat = Ppl) in a column on the right side of my display table, like this...ID_Name / ID_Note / Cat(egory) / Note
aus / 4Pop / Ppl / Note: Australia's population...
aus / 4PopG / Ppl / Note: Population growth...
can / 5Econ / Econ / Note: Canada's economy...
usa / 4Pop / Ppl / Note: The United State's population...
usa / 4PopG / Ppl / Note: Population growth in the U.S....
usa / 5Econ / Econ / Note: The U.S. economy is...
Notice that only footnotes from the PEOPLE category - cia_notes.Cat = Ppl - are included. Later, I'm going to use str_replace to change the footnote codes to superscript numbers. So if Pop(ulation) is represented by the footnote 1 and Population Growth by 3, my table might look like this:aus / 48 million / 25 / PopPopG
can / 60 million / 26 /
usa / 300 million / 28 / PopPopG
So the first thing I need to do is join the table cia_notes in a way that...aus / 48 million / 25 / 1,3
can / 60 million / 26 /
usa / 300 million / 28 / 1,3
1) Selects data only from rows where Cat = Ppl
2) But doesn't limit displays to countries that are represented by Ppl notes. In other words, Canada's population, etc. will still be display, even though it has no people footnotes.
3) I also need to display, where appropriate, multiple note codes (or superscript numbers) in each cell, rather than just one.
I added a second join, as follows:
It basically works, except that it only displays the FIRST footnote, yielding this...PHP Code:$res = mysql_query ("SELECT * FROM cia_ppl CP
LEFT JOIN gw_geog GG on GG.IDArea = CP.ID_Name
LEFT JOIN cia_notes CN on CN.IDName = CP.ID_Name
WHERE CP.Pop != 0") or die (mysql_error());
instead of this:aus / 48 million / 25 / Pop
can / 60 million / 26 /
usa / 300 million / 28 / Pop
So, if anyone can see where I'm headed, can you show me how to modify my query or PHP display, so that all relevant footnotes are displayed? And can you also show me how to limit the footnotes my script searches to PEOPLE footnotes (Cat = 'Ppl'), without zapping countries that have no people footnotes at all?aus / 48 million / 25 / PopPopG
can / 60 million / 26 /
usa / 300 million / 28 / PopPopG
Thanks.









Bookmarks