onlyican Posted September 3, 2006 Share Posted September 3, 2006 HeyI am building a Advanced Search form for my site.One of the opetions is to get them to search for members from x countryNow all the countries are stored in the database to show on the registration formThereforCountries should not have mulitple variations(Example UK, United Kingdom, England....)But the ORigininal Database holds ALL countries. And I dont have members from every country (yet)So What I want to do is run a query against the members, to get there country,SimpleSELECT * FROM members GROUP BY countryBut also on this search form, I want to do simular things, for other fieldsI do not wants to have 6 queries runningSo I was thinking of running one query, Selecting everythingThen store the result in an arrayIs there a way, I can GROUP before putting in the arrayor run a query against the array to select unique entriesI was thinking of doing something like[code]<?php$query = "SELECT * FROM members";$result = mysql_query($query);$countries = array();$local = array();while($row = mysql_fetch_assoc($result)){if($row["country"] != $country_check){$countries[] = $row["country"];}$country_check = $row["country"];if($row["local"] != $local_check){$local[] = $row["local"];}$local_check = $row["local"];}?>[/code]Now I know that would workBut is there a better way to do itNOTE: There are more than 2 things I will run, this is just a mini exampleEDIT//:Sorry the above wont work cos they are not in orderSoSpainUSAUKUSAwill show like that Quote Link to comment Share on other sites More sharing options...
Barand Posted September 3, 2006 Share Posted September 3, 2006 If all you want is list of countries with membersSELECT DISTINCT country FROM members ORDER BY country Quote Link to comment Share on other sites More sharing options...
onlyican Posted September 3, 2006 Author Share Posted September 3, 2006 But the thing is I want to select other things as wellInstead of running 10 queriesThe way I am currently doing it is[code]<?php$query1 = "SELECT * FROM members WHERE pro_status = 'a'";$result1 = mysql_query($query1);while($row = mysql_fetch_assoc($result1)){if(!in_array($row1["country"], $countries)){$countries[] = $row1["country"];}if(!in_array($row1["local"], $locals)){$locals[] = $row1["local"];}}sort($countries)sort($locals);//The form which will display these?>[/code]Is that the best way, or can anyone recommend a better way Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.