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 Link to comment https://forums.phpfreaks.com/topic/41996-show-unique-record-help/ 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 Link to comment https://forums.phpfreaks.com/topic/41996-show-unique-record-help/#findComment-203614 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 Link to comment https://forums.phpfreaks.com/topic/41996-show-unique-record-help/#findComment-203617 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 Link to comment https://forums.phpfreaks.com/topic/41996-show-unique-record-help/#findComment-203633 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 Link to comment https://forums.phpfreaks.com/topic/41996-show-unique-record-help/#findComment-203655 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 Link to comment https://forums.phpfreaks.com/topic/41996-show-unique-record-help/#findComment-203669 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 Link to comment https://forums.phpfreaks.com/topic/41996-show-unique-record-help/#findComment-203686 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? Link to comment https://forums.phpfreaks.com/topic/41996-show-unique-record-help/#findComment-203760 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. Link to comment https://forums.phpfreaks.com/topic/41996-show-unique-record-help/#findComment-203764 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 Link to comment https://forums.phpfreaks.com/topic/41996-show-unique-record-help/#findComment-203769 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 Link to comment https://forums.phpfreaks.com/topic/41996-show-unique-record-help/#findComment-206645 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.