我有一个看起来像这样的模型
function find($where){
$arr = $this->db->get_where($this->table,$where)->result_array();
foreach ($arr as $value) {
$prod_id = $value["id"];
$value['image']=$this->db->get_where("photos",['prod_id'=>$prod_id])->result_array();
}
return $value;
}
它给了我这个数组
Array(
[id] => 70
[name] => rrwerwer
[count] => 234
[price] => 234.00
[description] =>
[user_id] => 20
[image] => Array
(
[0] => Array
(
[id] => 88
[prod_id] => 70
[link] => 1_HP8l7LMMt7Sh5UoO1T-yLQ37.png
)))
在我的控制器中,我尝试加载视图并将数组传递给它
$data = $this->productmodel->find(["user_id =" => $this->session->user["id"]]);
$this->load->view('myproduct', ["products" => $data]);
然后在视图中在数组上运行foreach并打印内容
<?php foreach($products as $prod){ ?>
<div class="productDiv">
<div class="productName">
<span class="productNameSpan">
<?=$prod["name"]?>
</span>
</div>
<div class="productPrice">
<label class="productPriceLabel">Գին: <?=$prod["price"]." դրամ"?></label>
</div>
<div class="productCount">
<label class="productCountLabel">Քանակ: <?=$prod["count"]."X" ?></label>
</div>
<div class="productDescribtion">
<label class="productDescribtipnLabel">Նկարագիր: <?=$prod["description"] ?></label>
</div>
<div class="seeMoreDiv">
<button class="seeMoreButton btn btn-success">
ՏԵՍՆԵԼ ԱՎԵԼԻՆ
</button>
</div>
</div>
它给我错误“非法的偏移名称,价格等...” 我该如何解决这个问题? 我需要打印产品信息并显示产品图片
答案 0 :(得分:2)
不要使用const std::optional<const T>
并尝试这样做
foreach()
仅在echo $products["price"];
上使用foreach()