使用 Opencart 创建自定义页面。我正在使用foreach
来显示customer
详细信息。
但customer
详情未显示。
以下代码:
.tpl
<?php foreach($dealerData as $invoice){ ?>
<label> <b>Dealer Name:</b> <?php echo $invoice['name']; ?></label><br>
<label><b>Dealer TIN Number:</b> <?php echo $invoice['tin_number'];?></label><br>
<?php } ?>
控制器
$query13 = $this->db->query("select concat(firstname, ' ', lastname) as name, tin_number from ".DB_PREFIX."customer where customer_id='".$customer_id."'");
$dataDelar = $query13->rows;
foreach ($dataDelar as $dealer) {
$data['dealerData'][] = array(
'name' => $dealer['name'],
'tin_number' => $dealer['tin_number']
);
}
答案 0 :(得分:1)
为什么要在控制器中放置查询?您有模型van数据库相关的功能。变量$ invoiceData1上的foreach应该可以工作,你可以在print_r中看到数组中有1个数组。你把print_r放在你的控制器里了吗?所以,是的,请看下面,也许你正在重写$ invoiceData1。
修改强>
您没有创建一个空数组来将值放入:
$query13 = $this->db->query("select concat(firstname, ' ', lastname) as name, tin_number from ".DB_PREFIX."customer where customer_id='".$customer_id."'");
$dataDelar = $query13->rows;
$data['dealerData'] = [];
foreach ($dataDelar as $dealer) {
$data['dealerData'][] = array(
'name' => $dealer['name'],
'tin_number' => $dealer['tin_number']
);
}