Reputation: 856
I have table like this :
ID USER1 USER2 USER3
1 D Y N
2 C B M
3 E R U
4 F Y A
5 G B K
How to filter and show 1 value Y & 1 value B instead 2 value Y and 2 value B in USER2 CODE:
$query = mysqli_query($conn,"SELECT USER2 FROM TABLE");
<p><select name="select" id="select">
<?php
while($row = mysqli_fetch_assoc($query))
{
echo '<option value='.$row["USER2"].'>'.$row["USER2"].'</option>';
}
?>
</select></p>
In Select control it show 2 value B and 2 value Y. I want it show 1 value Y and 1 value B (Unique value)
Upvotes: 0
Views: 68
Reputation:
Try:
$query = mysqli_query($conn,"SELECT DISTINCT USER2 FROM TABLE");
Upvotes: 1
Reputation: 2301
you should use distinct in your sql query. you can simply do some thing like this :
SELECT DISTINCT USER2 FROM TABLE where USER2 = Y or USER2 = B
here is a good starting point in sql DISTINCT keyword : http://www.w3schools.com/sql/sql_distinct.asp
Upvotes: 0
Reputation: 2393
If you want to show distinct values, you need to say so:
SELECT DISTINCT USER2 FROM TABLE
But your table design is likely to cause trouble down the road, if you need to handle more than three users…
Upvotes: 0