Jump to content

show unique record help?


vlowe

Recommended Posts

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

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

<?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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.