eibersji
eibersji

Reputation: 1216

get value of item_type in database and make it selected in options

I have this in my blade:

<select class="form-control" id="item_type" name="item_type">
   <option value="physical-goods" <?php if ($product->item_type="physical-goods") echo 'selected=" selected"'; ?>>Physical Goods</option>
   <option value="digital-downloads" <?php if ($product->item_type="digital-downloads") echo 'selected=" selected"'; ?>>Digital Downloads</option>
   <option value="credits" <?php if ($product->item_type="credits") echo 'selected=" selected"'; ?>>Credits</option>
</select>

now this is what it looks like, enter image description here

even though Sample Product is a Physical Good, so it should be

enter image description here

What is wrong with my code?

Upvotes: 0

Views: 41

Answers (1)

manjinder
manjinder

Reputation: 95

Use double equal to instaed of single ==

<?php if ($product->item_type`enter code here`=="digital-downloads") echo 'selected=" selected"'; ?>

<select class="form-control" id="item_type" name="item_type">
   <option value="physical-goods" <?php if ($product->item_type=="physical-goods") echo 'selected=" selected"'; ?>>Physical Goods</option>
   <option value="digital-downloads" <?php if ($product->item_type=="digital-downloads") echo 'selected=" selected"'; ?>>Digital Downloads</option>
   <option value="credits" <?php if ($product->item_type=="credits") echo 'selected=" selected"'; ?>>Credits</option>
</select>

Upvotes: 1

Related Questions