表格内容显示不正确

时间:2018-07-13 07:01:37

标签: php database codeigniter

我遇到了无法正确显示内容的问题:

我的名字一遍又一遍地显示
我的IKLAN(图片)也
但我的SIZE不会一遍又一遍地显示
好有趣
like this the eror

这是我的观点:

data.php

<thead>

            <tr>
            <?php $i = 1;?>
              <th>Nomer</th>
              <th>Nama</th>
              <th>Iklan</th>
              <th>Ukuran</th>
              <th>Aksi</th>
            </tr>
            </thead>

            <tbody>
            <tr>

            <?php
            $no = $this->uri->segment('3') + 1;
            foreach ($list as $l) {?>

    <td align="center"><h4><?php echo $i++; ?></h4></td>



    <td align="center"><h4><span style="font-weight:bold"><?php echo $l->nama_client?></span></h4></td>
    <td align="center"><h4><img src="./upload_iklan/<?php echo $l->iklan;?>" id="gambar_nodin" width="200"/></h4></td>
    <td align="center"><h3><?php echo $l->size_ads?></h3></td>

这是我的控制器:Iklan.php

public function __construct()
{
    parent::__construct();
    $this->load->model('iklan_model');
    $this->load->helper(array('form','url'));
    $this->load->library('form_validation','upload','pagination');
    $this->load->helper('url');
}

    public function dashboard()
{
     $data['konten'] = "dashboard";
     $this->load->view('index', $data);
 }

public function index($offset=0)
{
    $this->load->database();
    $data['list']=$this->iklan_model->show_iklan();
    json_encode($data);
    $this->load->library('pagination');
    $config['base_url'] = base_url();
    $config['total_rows'] = $data;
    $config['per_page'] = 10;
    $from = $this->uri->segment(3);
    $this->pagination->initialize($config);     
    $data['list'] = $this->iklan_model->data($config['per_page'],$from);
    $this->load->view('data',$data);
}

这是我的模特:

Iklan_model.php

public function __construct()
{
    parent::__construct();

}

function data($number,$offset){
    return $query = $this->db->get('client,size,advertisement',$number,$offset)->result();      
}

function jumlah_data(){
    return $this->db->get('data')->num_rows();
}

1 个答案:

答案 0 :(得分:0)

循环必须在标记之前启动,这样它将在每一行中打印适当的数据。

<?php
            $no = $this->uri->segment('3') + 1;
            foreach ($list as $l) {?>
<tr>         

    <td align="center"><h4><?php echo $i++; ?></h4></td>



    <td align="center"><h4><span style="font-weight:bold"><?php echo $l->nama_client?></span></h4></td>
    <td align="center"><h4><img src="./upload_iklan/<?php echo $l->iklan;?>" id="gambar_nodin" width="200"/></h4></td>
    <td align="center"><h3><?php echo $l->size_ads?></h3></td>
</tr>
<?php } ?>
相关问题