Skip to content

Instantly share code, notes, and snippets.

@ErMandeep
Created January 11, 2019 09:34
Show Gist options
  • Save ErMandeep/19425946aeb1ff083b6ab346a4b99e81 to your computer and use it in GitHub Desktop.
Save ErMandeep/19425946aeb1ff083b6ab346a4b99e81 to your computer and use it in GitHub Desktop.
fetch select option from database
<select class="form-control" name="product_category_id" data-placeholder="Choose a Category" tabindex="1">
<?php
$query = "SELECT * FROM category";
$select_image = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($select_image)){
$id = $row['id'];
$cat_title = $row['cat_title'];
?>
<option value="<?php echo $cat_title; ?>" <?php if($product_category_id==$cat_title) echo 'selected="selected"'; ?>><?php echo $cat_title; ?></option>
<?php } ?>
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment