获取数据库中item_type的值,并在选项中将其选中

时间:2018-09-04 09:21:17

标签: php laravel-5

我的刀片中有这个:

<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>

现在这是它的样子, enter image description here

即使样品产品是一种物理商品,也应该是

enter image description here

我的代码有什么问题?

1 个答案:

答案 0 :(得分:1)

使用双精度等于单精度==

<?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>