modigy Posted November 4, 2006 Share Posted November 4, 2006 Hey all,I've received so much help. Now I have another question. I have a query...both a FULLTEXT search and a multiple dropdown box search. But the client DB contains multiple book 'title' entries. I would like to know how to eliminate the duplicate entries in the DB and just get the 'Unique' entries with regard to the 'title' fields of the DB?Here's my 'partial' mysql/php code:[code] <?php $database=mysql_pconnect('localhost','jandj_root'); mysql_select_db('books');if ($topic) { $query="select * from jandj_jandj.books where theme = '".$topic."' and referenceNum=0";}if ($title) { if ($title == "a-f") $query="select * from jandj_jandj.books where (title between 'a' and 'f') and referenceNum=0"; if ($title == "g-l") $query="select * from jandj_jandj.books where (title between 'g' and 'l') and referenceNum=0"; if ($title == "m-r") $query="select * from jandj_jandj.books where (title between 'm' and 'r') and referenceNum=0"; if ($title == "s-z") $query="select * from jandj_jandj.books where (title between 's' and 'z') and referenceNum=0";}if ($author) { if ($author == "a-f") $query="select * from jandj_jandj.books where (author between 'a' and 'f') and referenceNum=0"; if ($author == "g-l") $query="select * from jandj_jandj.books where (author between 'g' and 'l') and referenceNum=0"; if ($author == "m-r") $query="select * from jandj_jandj.books where (author between 'm' and 'r') and referenceNum=0"; if ($author == "s-z") $query="select * from jandj_jandj.books where (author between 's' and 'z') and referenceNum=0"; } // query defined above $result=mysql_query($query);?>[/code]How might I adjust this code to 'eliminate' duplicates of 'title' field in the DB? If the results include a book called 'Clifford the Big Red Dog' I don't want 5 of these results...just the 'Unique' book 'title'. Later in the code I have pagination. Currently the query and the pagination works great, but because there are more than one entries for the same book 'title' the query creates listings that are unecessary for the USER.Any help and ALL help is appreciated in advance.Cheers,M Link to comment https://forums.phpfreaks.com/topic/26118-how-to-eliminate-duplicate-entries-in-db-results-of-query/ Share on other sites More sharing options...
doni49 Posted November 4, 2006 Share Posted November 4, 2006 Can you show me an example of what's returned? My first thought is to use arry_unique against an array that's been returned from the query.www.php.net/array_unique Link to comment https://forums.phpfreaks.com/topic/26118-how-to-eliminate-duplicate-entries-in-db-results-of-query/#findComment-119443 Share on other sites More sharing options...
toplay Posted November 4, 2006 Share Posted November 4, 2006 Try to use distinct as in:select DISTINCT bk.title, bk.specific_column from jandj_jandj.books bk where ... Link to comment https://forums.phpfreaks.com/topic/26118-how-to-eliminate-duplicate-entries-in-db-results-of-query/#findComment-119493 Share on other sites More sharing options...
modigy Posted November 6, 2006 Author Share Posted November 6, 2006 Thanks Guys!!This is what I ended up with and it was a big help?[code]<?phpif ($topic) { $query="select * from jandj_jandj.books where theme = '".$topic."' and referenceNum=0 GROUP BY 'title' ASC";}if ($title) { if ($title == "a-f") $query="select * from jandj_jandj.books where (title between 'a' and 'f') and referenceNum=0 GROUP BY 'title' ASC"; if ($title == "g-l") $query="select * from jandj_jandj.books where (title between 'g' and 'l') and referenceNum=0 GROUP BY 'title' ASC"; if ($title == "m-r") $query="select * from jandj_jandj.books where (title between 'm' and 'r') and referenceNum=0 GROUP BY 'title' ASC"; if ($title == "s-z") $query="select * from jandj_jandj.books where (title between 's' and 'z') and referenceNum=0 GROUP BY 'title' ASC";}if ($author) { if ($author == "a-f") $query="select * from jandj_jandj.books where (author between 'a' and 'f') and referenceNum=0 GROUP BY 'author' ASC"; if ($author == "g-l") $query="select * from jandj_jandj.books where (author between 'g' and 'l') and referenceNum=0 GROUP BY 'author' ASC"; if ($author == "m-r") $query="select * from jandj_jandj.books where (author between 'm' and 'r') and referenceNum=0 GROUP BY 'author' ASC"; if ($author == "s-z") $query="select * from jandj_jandj.books where (author between 's' and 'z') and referenceNum=0 GROUP BY 'author' ASC"; }?>[/code]Again much appreciated! ;DM Link to comment https://forums.phpfreaks.com/topic/26118-how-to-eliminate-duplicate-entries-in-db-results-of-query/#findComment-120622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.