简体   繁体   English

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

[英]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, 现在看起来像这样 在此处输入图片说明

even though Sample Product is a Physical Good, so it should be 即使样品产品是一种物理商品,也应该

在此处输入图片说明

What is wrong with my code? 我的代码有什么问题?

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM