mysql order by the same as a list that i have in a variable -
mysql order by the same as a list that i have in a variable -
i pulling info has cities attached , info in order shows current city first, cities in order distance city searched. have cities in order want them shown in array called $nearby_city_array. there way pull data, in order, according shows in array?
$query = "select username, city, state ... city = '" . $city . "' state = '" . $state . "' order " . $nearby_city_array . "; $result = mysql_query($query, $db) or die(mysql_error($db)); any ideas great thanks.
while have found improve solution, i.e. 1 using info stored in database, else visiting question might search solution original question.
this idea:
create temporary table tmp_order (cntup integer auto_increment, city varchar(100)) insert tmp_order (city) values ('a'), ('b'), ... -- order select <fields> mytable bring together tmp_order using (city) order cntup this creates temporary table containing info in order in list. if bring together table original query , order result row id in temp table, want.
as said, if can omit list , utilize info nowadays in db, better.
mysql
Comments
Post a Comment