Hi I would like to have it to work with two fields, both id and text but I cant even get this to work.
I get a post from the database to update. If I have a ordinary optionlist. It views the selected value and I can change option and save it to the database.
This works:
<select name="ddlLinkType" title="<?php echo $row_visa_link['LinkType']; ?>">
<option value="" <?php if (!empty($row_visa_link['LinkType']) && $row_visa_link['LinkType'] == '' ) echo 'selected = "selected"'; ?>></option>
<option value="Styrelsen" <?php if (!empty($row_visa_link['LinkType']) && $row_visa_link['LinkType'] == 'Styrelsen') echo 'selected = "selected"'; ?>>Styrelsen</option>
<option value="Alla" <?php if (!empty($row_visa_link['LinkType']) && $row_visa_link['LinkType'] == 'Alla') echo 'selected = "selected"'; ?>>Alla</option>
<option value="Option3" <?php if (!empty($row_visa_link['LinkType']) && $row_visa_link['LinkType'] == 'Option3') echo 'selected = "selected"'; ?>>Option3</option>
</select>
But I would like to get the options dynamic from database table. I have tried many things now but nothing works. I am so confused and everything is messed up right now. I am trying to generate the optionlist without loosing the function that it shows the selected value from the post to be updated.
This doesnt work:
<select name="ddlLinkCategory" title="<?php echo $row['LinkCatID']; ?>">
<?php while($row = mysqli_fetch_assoc($resultCategoy)) { ?>
<!-- Dont know how to solve this-->
<option value="<?php($row['LinkCatID'])?>" <?php if (!empty($row_visa_link['LinkCategory']) && $row_visa_link['LinkCategory'] == $row['LinkCatID']) echo 'selected = "selected"'; ?>>$row['LinkCatID']</option>
<?php }} ?>
</select>
Thank You.
</div>
This code is wrong:
<select name="ddlLinkCategory" title="<?php echo $row['LinkCatID']; ?>">
<?php while($row = mysqli_fetch_assoc($resultCategoy)) { ?>
You dont acces to <?php echo $row['LinkCatID']; ?>
in line 1, $row is defined in line 2.
Thank You! Now it Works :)
<select name="ddlLinkCategory" title="<?php echo $row_visa_link['LinkCategory']; ?>">
<?php while($row = mysqli_fetch_assoc($resultCategory)) { ?>
<option value= "<?php echo($row['LinkCatID'])?>"<?php if (!empty($row_visa_link['LinkCategory']) && $row_visa_link['LinkCategory'] == $row['LinkCatID']) echo 'selected = "selected"'; ?>> <?php echo $row['LinkCatID']?></option>
<?php }} ?>
</select>
</div>