Gruzin Posted February 11, 2007 Share Posted February 11, 2007 Hi everyone, I'am having some trouble with mysql select... say I have a field DrugID (INT) and there are some records in it (2, 6, 12, 12). if there are two or more same records, like 12 three times, how can I detect that? hope you understand me, if not please let me know... Thanks, George Link to comment https://forums.phpfreaks.com/topic/38020-phpmysql-question/ Share on other sites More sharing options...
almightyegg Posted February 11, 2007 Share Posted February 11, 2007 $query = mysql_query("SELECT * FROM `table` WHERE DrugID='12'"); $query2 = mysql_num_rows($query); //counts how many ids = 12 Link to comment https://forums.phpfreaks.com/topic/38020-phpmysql-question/#findComment-181988 Share on other sites More sharing options...
Gruzin Posted February 11, 2007 Author Share Posted February 11, 2007 Thanks but, I don'r really know exact number, I mean: $query = mysql_query("SELECT * FROM `table` WHERE DrugID='$var'"); Thanks, George Link to comment https://forums.phpfreaks.com/topic/38020-phpmysql-question/#findComment-181992 Share on other sites More sharing options...
Jessica Posted February 11, 2007 Share Posted February 11, 2007 So what's the problem? Link to comment https://forums.phpfreaks.com/topic/38020-phpmysql-question/#findComment-182000 Share on other sites More sharing options...
Gruzin Posted February 11, 2007 Author Share Posted February 11, 2007 OK, here is my test script: $apt = mysql_query("SELECT DrugRemainder.MatID,Drugstores.DrugID FROM DrugRemainder,Drugstores WHERE (DrugRemainder.MatID='$id' AND Drugstores.DrugID=DrugRemainder.DrugID)"); and I don't want to show same results, I mean if there is a record 12 three times I want to count it as one. Thanks, George Link to comment https://forums.phpfreaks.com/topic/38020-phpmysql-question/#findComment-182004 Share on other sites More sharing options...
Jessica Posted February 11, 2007 Share Posted February 11, 2007 Use the MYSQL DISTINCT keyword. http://dev.mysql.com/doc/refman/5.0/en/select.html Link to comment https://forums.phpfreaks.com/topic/38020-phpmysql-question/#findComment-182013 Share on other sites More sharing options...
Gruzin Posted February 11, 2007 Author Share Posted February 11, 2007 Yeeeee! Thanks jesirose, I'am happy Link to comment https://forums.phpfreaks.com/topic/38020-phpmysql-question/#findComment-182017 Share on other sites More sharing options...
Jessica Posted February 11, 2007 Share Posted February 11, 2007 Also, if you're trying to find out how many, not just get unique, you can use count() Link to comment https://forums.phpfreaks.com/topic/38020-phpmysql-question/#findComment-182022 Share on other sites More sharing options...
Gruzin Posted February 11, 2007 Author Share Posted February 11, 2007 OK, but DISTINCT works just fine, Thank you again, George Link to comment https://forums.phpfreaks.com/topic/38020-phpmysql-question/#findComment-182026 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.