I have this table called studien:

I want to create a dropdown menu that first creates the 5 different categories (column category) with the following statement:
SELECT DISTINCT category FROM studien ORDER BY category ASC
In another queue, I gather name and id of the study names and compare their category with the category in the first queue.
For some reason, that doesn't work.
I read something about multi_query, but how can I compare the same value from the same table?
Thanks in advance
$selectvar = "SELECT * FROM studien ORDER BY name ASC";
$selectvar2 = "SELECT DISTINCT category FROM studien ORDER BY category ASC";
$result = mysqli_query($mysqli, $selectvar);
$result2 = mysqli_query($mysqli, $selectvar2);
while ($row2 = mysqli_fetch_array($result2)) {
echo "<option value='cat'>".utf8_encode($row2['category'])."</option>";
while ($row = mysqli_fetch_array($result)) {
if ($row2['category'] == $row['category']) {
echo "<option value=".$row['id'].">".utf8_encode($row['name'])."</option>";
}
}
}
utf8_encode(). It has barely any real use and is an artifact of old days.