I have a button with the data-id 3
. I want now in my mySQL database request to mark the option, that has the value 3
as selected.
<button data-id="3"></button>
<?php
$pdo = $db->query('SELECT * FROM members ORDER BY id ASC;');
while ($row = $pdo->fetch(PDO::FETCH_ASSOC)) {
echo "<option value=".$row['id'].">".$row['name']."</option>";
}
?>
So I think about something like
echo "<option value=".$row['id'].";
if ($row['id'] == data-id) {echo "selected";}
echo ">".$row['name']."</option>";
How can I achieve this?