Forum Moderators: coopster & phranque

Message Too Old, No Replies

Getting distinct values in a drop down lists

         

fintan

2:45 pm on Mar 3, 2004 (gmt 0)

10+ Year Member



Hi

I'm trying to get distinct values into a drop down list. I've used "DISTINCT" in the sql statement but to no effect. What I'm getting is

<option value="HSU001">Health & Safety Unit</option>
<option value="HSU001">Health & Safety Unit</option>

repeated 5 times. I thought if I could dump the id's and values into an associative array like this

$div = array($divcode => $division);

I could loop though them and only take out the distinct values. Any ideas? Thanks

fintan

ukgimp

2:50 pm on Mar 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



post your sql code.

I suspect you are linking tables? Correct?

eg

SELECT table1.field, table2.field FROM table1, table2 WHERE id = 'x'

But you are going to need an AND in your where clause

AND table1.table1id = table2.table1id

fintan

3:15 pm on Mar 3, 2004 (gmt 0)

10+ Year Member



Here it is.

SELECT TBLDIVISION.DIVCODE, TBLDIVISION.DIVISION, TBLUNIT.UNITID, TBLUNIT.UNIT FROM TBLDIVISION, TBLUNIT WHERE TBLUNIT.DIVCODE = TBLDIVISION.DIVCODE AND TBLDIVISION.DIVCODE IS NOT NULL ORDER BY TBLDIVISION.DIVISION, TBLUNIT.UNIT

I can take out all from one table but when I do the join, it prints out all matches but repeats them.