Stuart Felenstein wrote:

I have two tables

StatesTable CitiesTable
StateID(char) RunningCountID (int) State (varchar) StateID (char)
City (varchar)


Both are innodb tables, with CitiesTable having a
foreign key referencing StatesTable.StateID

Basically my first step here is to have some type of
print out:
New York         New York
                 Hastings on the Hudson
                 Elmira

California       Los Angeles
                 Santa Barbara
                 Riverside

Now I select both tables all fields, no reason to do a
join since the foreign key is in place.  Maybe that's
wrong.  Anyway the do line up correctly
but it's more like
New York        New York
New York        Hastings on the Hudson
New York        Elmira

This *is* a join. I expect you did something like

  SELECT State, City
  FROM StatesTable, CitiesTable
  WHERE StatesTable.StateID = CitiesTable.StateID;

The comma between the tables is the implicit join operator, with the join condition in the WHERE clause. See the manual for more <http://dev.mysql.com/doc/mysql/en/JOIN.html>.

So maybe that's the way it will print on a query
unless formatted.

You have 2 options. 1) You can code to only print the state when it changes. 2) If you are using mysql 4.1, you can do this in the query with the GROUP_CONCAT() function. See the manual for the details <http://dev.mysql.com/doc/mysql/en/GROUP-BY-Functions.html>.


That leads me to my second question, somewhat client
side, so I can take it somewhere else if it's wrongly
posted here.

I have 1 menu pull down and one list field next to it.
After I select some state from the pull down I want
the associated cities in the list.  Now I realize that
this has something to do with a variable being passed.

Right. Once the state is selected, you will have to code a way to send a query to retrieve the cities for that state, then build the city menu based on the results.


At the same time I'm wondering if that can be done via
a SQL statement.

Not sure what you mean here.

Sorry and thanks !
Stuart

Michael

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to