Mysql_query into an array

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
ankhmor
Forum Newbie
Posts: 12
Joined: Fri Jul 13, 2007 4:45 pm

Mysql_query into an array

Post by ankhmor »

Problem: How can I put the whole mysql_query into an array that I can use array_unique on?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Better yet, why not

Code: Select all

.. GROUP BY `fieldname`
in your sql statement the field you want unique?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

or DISTINCT.
User avatar
boo
Forum Commoner
Posts: 42
Joined: Mon Jul 02, 2007 11:30 am
Location: NY

Post by boo »

I think with distinct all of the fields that are returned would need to match rather than just 1 or 2 of the fields, but if that is what you are looking for then distinct would be the way to go. No reason to send back something you are not going to use.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

boo wrote:I think with distinct all of the fields that are returned would need to match rather than just 1 or 2 of the fields, but if that is what you are looking for then distinct would be the way to go. No reason to send back something you are not going to use.
It would be the same result as array_unique() with a lot of cruft removed, so I'm pretty sure ~ankhmor is looking for it. :)
User avatar
boo
Forum Commoner
Posts: 42
Joined: Mon Jul 02, 2007 11:30 am
Location: NY

Post by boo »

feyd wrote:It would be the same result as array_unique() with a lot of cruft removed, so I'm pretty sure ~ankhmor is looking for it. :)
You are right just looked it up in the manual after I posted since I was not sure if array_unique() looked at the whole string value.
ankhmor
Forum Newbie
Posts: 12
Joined: Fri Jul 13, 2007 4:45 pm

Post by ankhmor »

thanks guys. Highly apreciated
Post Reply