0

The problem in the image is, I only want Francis to be show in the drop down, when I click the first drop down. In order words, no duplication of names. I hope someone will help me. Thanks in advance. :)

Also here's my code. :)

          <tr>
            <td><label for="cname">Client Name:</label></td>
            <td><select name="cname" id="cname">
                    <option value="">Choose</option>
                    <?php
                        $result = mysqli_query($con, "SELECT ClientName, EventID FROM events");
                        while($row = mysqli_fetch_assoc($result)){
                            echo "<option value='{$row["ClientName"]}' data-eid='{$row["EventID"]}' >";
                            echo $row["ClientName"] . "</option>";
                        }
                    ?>
                </select>
            </td>
        </tr>
Francis Vargas
  • 57
  • 1
  • 1
  • 8
  • 2
    `SELECT DISTINCT`? – Siyual Sep 20 '16 at 15:26
  • SELECT DISTINCT ClientName, EventID FROM events. Is this right? :) – Francis Vargas Sep 20 '16 at 15:27
  • through reading all of the comments it appears the issue is because you have multiple Events with the client name Francis. your data structure clearly allows for more than 1 Francis so how do you know they would be the same person? Do you care or do you simply want to select all unique first names? If all unique first names then take EventId out of your dataset and use DSITINCT. SELECT DISTINCT ClientName from events.... – Matt Sep 20 '16 at 15:54

1 Answers1

2

Use distinct key word in the query that are loading the names.

$result = mysqli_query($con, "SELECT distinct ClientName FROM events");

Since a ClientName can be related with one or more EvenID you should not include EvenID in your query. If you decide to include both columns in your query you will get duplicated names.

Luis Teijon
  • 4,769
  • 7
  • 36
  • 57
  • @Francis Vargas Is that EventID different for each francis – Kiran Muralee Sep 20 '16 at 15:33
  • no, that EventID is used in the other codes, in the program. – Francis Vargas Sep 20 '16 at 15:35
  • 2
    when you write distinct your are deleting duplicated rows but in your query the name Francis seems to be related with one or more EventID and thats why Francis is showed more than once. Why are you having this columns in the same table? I think you must normalize your table and keep these columns apart. – Luis Teijon Sep 20 '16 at 15:35
  • 1
    @Francis Vargas Have a look http://stackoverflow.com/questions/11641270/mysql-select-all-columns-where-one-column-is-distinct – Kiran Muralee Sep 20 '16 at 15:37
  • @Francis Vargas If only one person Francis Vargas is there and he is having different event ids,one might not simply use client name,he should be using a client id. – Kiran Muralee Sep 20 '16 at 15:45
  • You want to eliminate Francis named which is duplicated but related to more than one EventID too. My question is, Which of those EventId will you show along with Francis name? I'm still suggesting that there is a problem of normalization here. Can you tell us all the fieds of your table? – Luis Teijon Sep 20 '16 at 16:41