I'm trying to populate radio buttons with data from MySQL.
I'd like the selected radio button to change colour, and the first element to be selected on page load.
How can I do this?
<div class="panel bg-product">
<?php
$stmt = mysqli_prepare($link, "SELECT id, name, price FROM products");
$stmt->execute();
$stmt->bind_result($prod_id, $prod_name, $prod_price);
while($stmt->fetch()) {
echo '<label><input type="radio" name="config-prod" value="'.$prod_id.'"> ' .$prod_name.'</label><br>';
}
$stmt->close();
?>
</div>
CSS:
.panel input[type="radio"]:checked + label{
font-weight: 700;
color: red;
transition: color 0.5s ease;
}
This CSS does not change the colour of the radio button when selected, nor is a radio button selected on load.