【问题标题】:Table content does not showing correctly表格内容显示不正确
【发布时间】:2018-07-13 07:01:37
【问题描述】:

我无法正确显示内容:

我的名字一遍又一遍地出现
我的 IKLAN(图片)也是
但我的 SIZE 没有一遍又一遍地显示
好搞笑
like this the eror

这是我的观点:

数据.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();
}

【问题讨论】:

  • 展示你对它的期望?它们在循环中,这就是为什么值会像你所说的那样一遍又一遍地显示
  • 该名称在我的表格中一遍又一遍地显示 MILI,iklan(image) 的每一行也显示相同的图像,但每行都会更改 SIZE
  • 我已经给了图片链接
  • 检查你的表是否有名称和图像名称不同?
  • 是的,一切都不一样了

标签: php database codeigniter


【解决方案1】:

循环必须在标签之前开始,这样它就会用正确的数据打印每一行。

<?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 } ?>

【讨论】:

  • hhmmm 好的,我试试
猜你喜欢
  • 1970-01-01
  • 2014-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-16
  • 1970-01-01
相关资源
最近更新 更多