Current location: Hot Scripts Forums » Programming Languages » PHP » Selecting only one of each item


Selecting only one of each item

Reply
  #1 (permalink)  
Old 08-11-04, 04:28 AM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
Selecting only one of each item

I have a huge number of rows in my mysql db.
from the column facility i want to be able to put those into a drop down list. one problem is that the several hundred words the same but i only need one of them. for example...the column looks like this

syslog
user
syslog
syslog
cron
auth
cron
auth
auth
mail
local7
syslog
local7

I want to be able to create a drop down list like this

syslog
auth
mail
local7
user
cron

Only having one of each item in it, no duplicates.How do i parse this in php?
Reply With Quote
  #2 (permalink)  
Old 08-11-04, 04:57 AM
uprightdog uprightdog is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
I'd look into using GROUP BY in your SQL query
Reply With Quote
  #3 (permalink)  
Old 08-11-04, 05:47 AM
darkfreak's Avatar
darkfreak darkfreak is offline
Newbie Coder
 
Join Date: Jun 2004
Location: Kuopio, Finland, Europe
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Hmm... I was left a bit unclear about this, but here's something:

SELECT DISTINCT columname FROM tablename ORDER BY columnname ASC

will select each value from the table column only once and order them alphabetically in growing order (ASC replaced by DESC would do the opposite).

Sorry if I understood wrong and told you just some basic stuff...

Last edited by darkfreak; 08-11-04 at 05:49 AM.
Reply With Quote
  #4 (permalink)  
Old 08-12-04, 07:38 AM
MasQ's Avatar
MasQ MasQ is offline
Newbie Coder
 
Join Date: Feb 2004
Location: Norway/Oslo
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Not sure if you helped him, but you sure made my day
__________________
**Schmmotch**
Reply With Quote
  #5 (permalink)  
Old 08-12-04, 09:40 AM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by darkfreak
Hmm... I was left a bit unclear about this, but here's something:

SELECT DISTINCT columname FROM tablename ORDER BY columnname ASC

will select each value from the table column only once and order them alphabetically in growing order (ASC replaced by DESC would do the opposite).

Sorry if I understood wrong and told you just some basic stuff...


works like a treat, thanks very much!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why won't select list item insert into database? gavacho PHP 2 12-05-08 06:38 PM
item search > item display eq1987 PHP 14 07-01-04 12:52 PM
mySQL: selecting values that do not exist bitesize PHP 9 02-20-04 11:47 AM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM
selecting directory's for drop down Squid44th PHP 2 12-17-03 09:16 AM


All times are GMT -5. The time now is 04:18 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.