Seems like sorting by group is not working on this one.
The variable $check_all is used to shown all the properties.
$check_all=$wpdb->get_results("select distinct town_village, suburb, state from $table where (concat(suburb,', ',state,', ',postcode)='$value' or concat(suburb,', ',postcode)='$value' or concat(suburb,', ',state,' ',postcode)='$value' or concat(suburb,', ',state)='$value' or CONCAT(town_village,', ',state) like '%$value%') Group by suburb,town_village,state", ARRAY_A);
Then I have this code to filter the output by searched inputted.
$sql_keywords.= "properties.town_village in ('".$check_all[0]['town_village']."') AND properties.state in ('".$check_all[0]['state']."') AND ";
As example the results must be like this all suburb 'Manila' must show first. Please see screenshot http://prntscr.com/inpgjn
But the result I'm getting is in random. The search suburb was shown in random places in results.
EDITED: Here is the current result of the code I shown above
Search by 'Manila' http://prntscr.com/inppj8
The result I want when they search 'Manila' is to show all the Manila at first of the results http://prntscr.com/inpgjn
Please see code for the this function
function lookup_string($value, $sql_keywords, $sur_suburbs='0'){
global $wpdb;
$suburb_region=$wpdb->get_results("show columns from suburb_region");
$table=($suburb_region)?'suburb_region':'properties';
if($sur_suburbs==1){
if(strpos($value,',')!==false){
$check_all=$wpdb->get_results("select distinct town_village, suburb, state from $table where (concat(suburb,', ',state,', ',postcode)='$value' or concat(suburb,', ',postcode)='$value' or concat(suburb,', ',state,' ',postcode)='$value' or concat(suburb,', ',state)='$value' or CONCAT(town_village,', ',state) like '%$value%') Group by suburb,town_village,state", ARRAY_A);
$check_suburb=$wpdb->get_var("select distinct suburb from $table where CONCAT(suburb,', ',state, ', ',postcode) like '%$value%'");
}
if($check_all){
$sql_keywords.= "properties.town_village in ('".$check_all[0]['town_village']."') AND properties.state in ('".$check_all[0]['state']."') AND ";
}
}
}
Expected order of query shown below. Right now I'm getting suburb in random.
suburb | state |
----------------------
Manila | Metro |
Manila | Metro |
Manila | Metro |
Manila | Metro |
Pasay | Metro |
Makati | Metro |
ETC | Metro |