how to get the duplicate data's array from the coming data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
djdon11
Forum Commoner
Posts: 90
Joined: Wed Jun 20, 2007 5:03 pm

how to get the duplicate data's array from the coming data

Post by djdon11 »

Hi friends

i have a while loop running in my coding which is fatching some data from the database. there are duplicacy of some names in the records means there are some common names share by many users. now i need to form a array of each name which is more than one times in my records. note i want each name means if the name "David" coming three times in my records than the name "David" should be three times in the array.


Thanks if anybody can help me for this.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: how to get the duplicate data's array from the coming data

Post by Kieran Huggins »

Code: Select all

SELECT name, COUNT(name) AS number FROM sometable GROUP BY name ORDER BY number DESC
Not sure how to add the WHERE clause to filter the results though, maybe someone else knows off the top of their head?

Wait... you're doing DB selects in a WHILE loop? Why?
Post Reply