Good Day,

Can anyone help me how to delete duplicate record in a dropdown list? I have a database with the column "material type" and "material model". For every material type there are a lot of model, so everytime I add record to the database, the column material type will have duplicate records.

Example:

Material Type Material Model
Gatsby wax
Gatsby clay
Gatsby gel

When I query the database, all gatsby record will appear in the dropdown list wherein I just want one record of gatsby to appear, please help me how to eliminate duplicate records with this.

<?php

        $con = mysql_connect("localhost","root","");
            if (!$con)
            {
                die('Could not connect: ' . mysql_error());
            }

            mysql_select_db("ppic", $con);
            $sql="SELECT idNumber, mType FROM tableItem"; 
            $result= mysql_query($sql);
            $options=""; 

            while ($row=mysql_fetch_array($result)) {

            $id=$row["idNumber"];
            $thing=$row["mType"];
            $options.="<OPTION VALUE=\"$id\">".$thing.'</option>';
} 

    ?>

<OPTION VALUE=0><select>
<?php echo $options ?>
</select></td>

above is the code
Hope to read your reply soon.

Thank you very much

Change This

$sql="SELECT idNumber, mType FROM tableItem";

To

$sql="SELECT idNumber, mType FROM tableItem  GROUP BY mType";

Dude your genius it works great, thanky you very much :)

Good Day,

Another problem arise, it works well with the material type, however when I enter the the material model see below example:

mType -------------mModel
gatsby ------------ wax
gatsby ------------ clay
gatsby ------------ gel
out of bed -------- wax

when I enter the dropdown list for material type there is no problem, but when I enter the dropdown list for material model, in this case if I enter the material type as "out of bed" the material model that should be appearing on the other drop down menu should be wax, but it appears all wax, clay, and gel, is there any way how to filter it?

<?php

        $con = mysql_connect("localhost","root","");
            if (!$con)
            {
                die('Could not connect: ' . mysql_error());
            }

            mysql_select_db("ppic", $con);
            //$sql="SELECT idNumber, mType FROM tableItem"; 
                $sql="SELECT idNumber, mItem FROM tableItem";
            $result= mysql_query($sql);
            $options=""; 

            while ($row=mysql_fetch_array($result)) {

            $id=$row["idNumber"];
            $thing=$row["mItem"];
            $options.="<OPTION VALUE=\"$id\">".$thing.'</option>';
} 

    ?>

<OPTION VALUE=0><select>
<?php echo $options ?>
</select></td>

Please Help,

Thank You Very Much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.