Opencart自定义页面foreach没有显示

时间:2017-04-24 13:40:44

标签: foreach opencart

使用 Opencart 创建自定义页面。我正在使用foreach来显示customer详细信息。

customer详情未显示。

以下代码:

.tpl

    <?php foreach($dealerData as $invoice){ ?>
    <label> <b>Dealer Name:</b>&nbsp;<?php echo $invoice['name']; ?></label><br>
    <label><b>Dealer TIN Number:</b>&nbsp;<?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']
            );
        }

1 个答案:

答案 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']
  );
}