vlowe Posted March 9, 2007 Share Posted March 9, 2007 Hey, I am using ODBC to get records from an access database. i want to produce a list of composers as a dropdown box, so i did this: while (odbc_fetch_row($res)) { $composer=odbc_result($res,"ARTIST"); $comid=odbc_result($res,"ORDER"); echo '<option value="' .$comid. '">' .$composer. '</option>'; } but this shows the composers name duplicate times depending on how many albums are available by that composer. how can i strip out the duplicates and show each composers name once? thanks for any help you can provide Quote Link to comment Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 The answer is in the query, without that your at a loss. Best bet is to post the query so that can be re-written properly. --FrosT Quote Link to comment Share on other sites More sharing options...
vlowe Posted March 9, 2007 Author Share Posted March 9, 2007 Yea i was just hinking that, here it is. select ARTIST, ORDER from WEBDATA where (order BETWEEN 15 AND 1000) ORDER BY ARTIST Quote Link to comment Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 Wow, this DB must not be in 3NF. That would of made this a lot easier. One way (half-assed to do it) is this: <?php $comids=array(); while (odbc_fetch_row($res)) { if (!in_array($comids)) { $composer=odbc_result($res,"ARTIST"); $comid=odbc_result($res,"ORDER"); $comids[]=$comid; echo '<option value="' .$comid. '">' .$composer. '</option>'; } } ?> Hope that works for a temporary fix. --FrosT Quote Link to comment Share on other sites More sharing options...
craygo Posted March 9, 2007 Share Posted March 9, 2007 <?php echo "<select name=composer>\n"; $sql = "select ARTIST, ORDER from WEBDATA where (order BETWEEN 15 AND 1000) ORDER BY ARTIST"; $res = odbc_exec($dbconnect, $sql); while ($r=odbc_fetch_array($res)){ echo "<option value='".$r['ORDER']."'>".$r['ARTIST']."</option>\n"; } echo "</select>\n"; ?> Ray Quote Link to comment Share on other sites More sharing options...
vlowe Posted March 9, 2007 Author Share Posted March 9, 2007 cheers guys but both solutions have given the same original result. hmmmmmmm Quote Link to comment Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 craygo would be the one to go with. Like I said mine was half-assed, craygo's is the correct way to go about it. --FrosT Quote Link to comment Share on other sites More sharing options...
vlowe Posted March 9, 2007 Author Share Posted March 9, 2007 Yo frost, when i said both have given the original result i meant both ways have not worked, the still show multiple entries for the same composers. any other ideas? Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 9, 2007 Share Posted March 9, 2007 LIMIT 1 on the end of query ok. Quote Link to comment Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 My bad man, on my half-assed way, I messed up on the "in_array" function, this is out it should be. <?php $comids=array(); while (odbc_fetch_row($res)) { if (!in_array($comid, $comids)) { $composer=odbc_result($res,"ARTIST"); $comid=odbc_result($res,"ORDER"); $comids[]=$comid; echo '<option value="' .$comid. '">' .$composer. '</option>'; } } ?> --FrosT Quote Link to comment Share on other sites More sharing options...
vlowe Posted March 13, 2007 Author Share Posted March 13, 2007 no still dint work. got it working tho using SELECT DISTINCT in sql query.. DOE Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.