我已经建立了一个小的网络商店,我想显示这个<div class ="data-plan"></div>
只为一个单一的产品。我的数据库表,我想从那里匹配这个ID是所谓的sb_files
,它有这些字段id
table_id
path
type
slide_link
,所以我试图让我的代码去通过该表,搜索id(13040100),如果匹配,则显示div,否则显示一个空div。我使用的是基于php的Yii2框架。到目前为止,我已经尝试过了
<?php if($product->$this->id('13040100')): ?>
<ul>
<?php
$index = 1;
foreach($product->() as $prd):
if(strpos($prd->getPath(), '13040100') == true) {
?>
<div class="wrap">
<div class="data-plan" style="height:20px; width:65px; background-color:#00a651; float:right;color:white;margin:10px;text-align:center;"><a href="#" style="text-decoration:none;color:white;">A+++</a> </div>
<div class="data-plan" style="height:20px; width:65px; background-color:#ed1c1c; float:right;color:white;margin:10px;"><a href="" style="text-decoration:none;color:white;">Datu lapa</a> </div>
</div>
<?php
$index++;
}
endforeach;
?>
</ul>
<?php else: ?>
<div class="wrap">
</div>
<?php endif; ?>
2条答案
按热度按时间wnvonmuf1#
我自己对Yii2框架也不是很熟悉,但是你确定
$product->$this->id('13040100')
是正确的吗?我觉得很奇怪,它不应该是$product->id('13040100')
之类的吗?8fsztsew2#
解决方案比我想象的要简单得多,只要想得简单就行了