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

Link to comment
Share on other sites

<?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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.