php - removing avoiding duplicates from resultset -
i have query:
$relevantwords = {"one" , "two" , "three" } ; foreach ($relevantwords $word) { $query .= "select * delhi_items heading '%$word%' , id!={$entry_row['id']} , visible=1 union " ; } $query = implode( " " , explode(" " , $query , -3) ) ; $query .= " order time_stamp desc limit 0, 20 " ; $result_set = mysql_query($query, $connection); this causes several duplicates in resultset. there way detect , remove these duplicates resultset ? know should try avoid duplicates in first place, unable figure out.
also tried distinct keyword, didn't work (because loop, same entry fetched again , again).
laslty kind of amateur please tell me if doing fundamentally uncool such long sql query in loop.
thanks
i try have 1 select , no union , distinct. faster query:
$relevantwords = {"one" , "two" , "three" } ; $querycondition = "" ; foreach ($relevantwords $word) { $querycondition .= " heading '%$word%' or" } $querycondition = substr($querycondition ,0 ,strlen($querycondition)-2 ) ; $query = " select * " . " delhi_items " . " ( " . $querycondition . " ) " . " , id!={$entry_row['id']} " . " , visible=1 " . " order time_stamp desc " . " limit 0, 20 " ; $result_set = mysql_query($query, $connection);
Comments
Post a Comment