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
jrucifer
Forum Commoner
Posts: 32 Joined: Fri May 13, 2005 2:36 pm
Location: phoenix
Post
by jrucifer » Fri Feb 10, 2006 3:30 pm
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 » Fri Feb 10, 2006 3:34 pm
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 » Fri Feb 10, 2006 3:41 pm
great, even more simple than i was hoping for. Thanks a lot.
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Fri Feb 10, 2006 9:53 pm
I wonder why he would need this though... it's generally good practice to assign a non-meaningful id to all entries in databases.
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sat Feb 11, 2006 6:06 am
Doesn't it have to be similar to this?
Code: Select all
select distinct `distinctfield`, `otherfield`, `anotherfield` from `thetable` group by `distinctfield`
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Feb 11, 2006 9:29 am
using group by or distinct will generally do the job, however using both can be overkill.