brob Posted January 31, 2007 Share Posted January 31, 2007 Hi can anyone help. I'm running a db query and adding the content into an array. I need to check if there are any duplicates in the array. Can someone help me do this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/36505-match-values-in-an-array/ Share on other sites More sharing options...
c4onastick Posted January 31, 2007 Share Posted January 31, 2007 There's a way to do this in MySQL, the function elludes me at the moment (something like defined() or unique() ). Check out this, http://dev.mysql.com/doc/refman/5.1/en/index.html It may get you going in the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/36505-match-values-in-an-array/#findComment-173767 Share on other sites More sharing options...
Orio Posted January 31, 2007 Share Posted January 31, 2007 Use SQL-Distinct. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/36505-match-values-in-an-array/#findComment-173774 Share on other sites More sharing options...
c4onastick Posted January 31, 2007 Share Posted January 31, 2007 Use SQL-Distinct. Ah! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/36505-match-values-in-an-array/#findComment-173863 Share on other sites More sharing options...
brob Posted February 1, 2007 Author Share Posted February 1, 2007 Hi I don't want to get rid of the duplicates i want to identify them and merge the results. Canthis be done? Quote Link to comment https://forums.phpfreaks.com/topic/36505-match-values-in-an-array/#findComment-174466 Share on other sites More sharing options...
HuggieBear Posted February 1, 2007 Share Posted February 1, 2007 OK, can you elaborate a little. How are you creating the array, Which database column forms the key (if any), Likewise for the value, What do you want to look for duplicates in? Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/36505-match-values-in-an-array/#findComment-174480 Share on other sites More sharing options...
brob Posted February 1, 2007 Author Share Posted February 1, 2007 Hi I want to add the data from this query into an array $result=mysql_query("select start_time, end_time, room_id, name, description, mobile_no from mrbs_entry, mrbs_tel where mrbs_entry.room_id = mrbs_tel.contact_id and start_time >= '$today_start' and end_time < '$today_end'"); while ($i = mysql_fetch_row($result)) { there isn't a primary key but the field I want to match against is the room_id. If there are more than 2 room_id's I want t pull out their information. Can you help? Quote Link to comment https://forums.phpfreaks.com/topic/36505-match-values-in-an-array/#findComment-174533 Share on other sites More sharing options...
HuggieBear Posted February 1, 2007 Share Posted February 1, 2007 My SQL knowledge is a little bit lacking here, but someone who's more confident with it maybe able to correct me. I think that you could use count() along with GROUP BY and HAVING to achieve the result that you want. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/36505-match-values-in-an-array/#findComment-174558 Share on other sites More sharing options...
brob Posted February 1, 2007 Author Share Posted February 1, 2007 sorry cold you explain that one a bit more Quote Link to comment https://forums.phpfreaks.com/topic/36505-match-values-in-an-array/#findComment-174661 Share on other sites More sharing options...
yzerman Posted February 1, 2007 Share Posted February 1, 2007 $result=mysql_query("select start_time, end_time, room_id, name, description, mobile_no from mrbs_entry, mrbs_tel where mrbs_entry.room_id = mrbs_tel.contact_id and start_time >= '$today_start' and end_time < '$today_end'"); while ($row = mysql_fetch_array($result)) { echo $row[0] } use mysql_fetch_array instead of mysql_fetch_row, the mysql query should do the rest. Quote Link to comment https://forums.phpfreaks.com/topic/36505-match-values-in-an-array/#findComment-174716 Share on other sites More sharing options...
Psycho Posted February 1, 2007 Share Posted February 1, 2007 brob, you are using a lot of generic terms that could mean many things: "Hi I don't want to get rid of the duplicates i want to identify them and merge the results." Soa re you sayting if there are two records with the same id you want to have only one record with some data fields combined? "If there are more than 2 room_id's I want t pull out their information." Pull out to where and do what with it? How about you show us: 1) Your current query and 2) An example of the data from two records and how you want to convert/display it. I'm thinking there is probably a very easy solution that does not require a new query or even an array, but you are not giving enough information. Quote Link to comment https://forums.phpfreaks.com/topic/36505-match-values-in-an-array/#findComment-174762 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.