mysql_fetch_array question

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
jrucifer
Forum Commoner
Posts: 32
Joined: Fri May 13, 2005 2:36 pm
Location: phoenix

mysql_fetch_array question

Post by jrucifer »

this is a rather simple question, so i hope there is a simple answer...

is there any way to have mysql_fetch_array output only 1 of many similar entries in the database?

for example, if these were entries in my database:

a
b
a
b
b
c
c
c

the output would be:

a
b
c

Thanks for any help.
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post by LiveFree »

The sql would be ...

"SELECT DISTINCT * FROM table"
jrucifer
Forum Commoner
Posts: 32
Joined: Fri May 13, 2005 2:36 pm
Location: phoenix

Post by jrucifer »

great, even more simple than i was hoping for. Thanks a lot.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I wonder why he would need this though... it's generally good practice to assign a non-meaningful id to all entries in databases.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Doesn't it have to be similar to this?

Code: Select all

select distinct `distinctfield`, `otherfield`, `anotherfield` from `thetable` group by `distinctfield`
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

using group by or distinct will generally do the job, however using both can be overkill.
Post Reply