|
-
Jun 1st, 2002, 02:37 PM
#1
Thread Starter
Lively Member
grouping people
This is kind of hard to explain what i mean but here goes....
i have a table with a number of people, similar to an address book... i would like to sort them alphabetically by name, grouped by the city they live in but i would like the output to be like so in the html
CITY #1 - New york
Person #1's detail - from new york
Person #3's detail - from new york
CITY #2 - LA
Person #2's detail - from LA
CITY #3 - Chicago
Person #3's detail - from Chicago
- now i already know how to get information from the database and what not, and i know the html for it, but what i cant figure out is how do i have it spit out each City and put the people under that city that live there
Hope this makes some sense
-
Jun 1st, 2002, 04:13 PM
#2
Member
i didn't really understand your problem, but may be the SQL SELECT clause "GROUP BY" is what you need?
-
Jun 3rd, 2002, 12:16 PM
#3
Thread Starter
Lively Member
not really because i want to actually OUTPUT the group name...i think i could do a group by and then do an if statement to see if its changed, but i'm not having much luck.
-
Jun 3rd, 2002, 05:38 PM
#4
you can do 2 queries, as that might be the best bet.
PHP Code:
$sql = mysql_query("select distinct state from table");
while($row = mysql_fetch_array($sql)){
$sql2 = mysql_query("select name from table where state = '".$row["state"]."' ");
while($row2 = mysql_fetch_array($sql2)){
//get fileds here and display
}
}
something like that
-
Jun 3rd, 2002, 06:39 PM
#5
Fanatic Member
wont it work if you sort the names then grou them by location ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|