I am trying to get my choice to show the selected category from my database in a dropdown. I can only show this when I hit the submit button.
<?php
(isset($_POST["kategori"])) ? $kategori = $_POST["kategori"] : $kategori=1;
$sql = "SELECT * FROM kategori"
$result = mysqli_query($db, $sql);
while($produkt = mysqli_fetch_array($result)) {
?>
<option <?php if ($kategori == $produkt['kategori_id'] ) echo 'selected'; ?>
value="<? echo $produkt['kategori_id']; ?>">
<? echo $produkt['kategori_navn']; ?></option>
<?php
}
?>
Apparently I am getting the value from POST and so it shows the category first when I hit submit.
I need to make a selection from my database with the product ID of the product and use its ID to mark which category is installed.
And I can't figure out how to do it.
source
to share