I don't know how to phrase this question nor how to look it up properly. I have tried many searches worded differently but haven't come up with anything yet. I am very new to mysql and php so sorry for any noobish remarks.
+---+-----------+---------+
|state |County |people |
+---+-----------+---------+
|state1 | a | person1 |
|state1 | a | person2 |
|state1 | b | person3 |
|state2 | c | person4 |
|state2 | d | person5 |
+---+-----------+---------+
This is a very short example of the table that i am dealing with. I am looking for a way to get the first county for each state. This is a webpage for a map of all the different people's location of where they mentor students, so there is a lot more to the table.
Choose State
-State1 -State2
Counties in State1:
-a -b
County a in State1:
-Person1
-Person2
I want to have it so when you click state1's href link, it will have county a as the default to show which people are in that state. Otherwise it will show the last selection or default to a county in a different state. Then you can click any of the county's href links that show up for that state.
I keep thinking that i can just search for state1 in the table and then get the first county but i don't know how to do that. I keep thinking i can do:
($row['State'])['County']
but that seems really illegal with php
Your usage of this thing seems completely unrelated (although perfectly fine), but to answer your literal question, you can use LIMIT
:
select county -- we want the county name
from table -- your table name here
where state='state1' -- your search criteria
order by county -- alphabetical ordering to select the first county (if needed)
limit 1 -- and we only care about the first!