gpt4 book ai didi

php - 仅显示包含项目列表中的图像的数据

转载 作者:行者123 更新时间:2023-11-29 21:07:46 25 4
gpt4 key购买 nike

这里我有一个包含图像和非图像的项目列表,我想显示包含图像的项目..这是我的查看页面

 <?php foreach($clients as $row){?>
<?php $images=json_decode($row->image);{?>
<?php if($images){;?>
<div class="client"> <img src="<?php echo base_url();?>images/<?php echo $images[0];?>" alt="" class="grayscale wow bounceIn" data-wow-delay=".1s"> </div>

<?php }}}?>

这是我的 Controller ..

public function index($p_id=null)
{
$data['active_mn']='index';
$data['clients']=$this->Nowaste_model->get_clients($p_id=4,6,0);
$this->load->view('index',$data);
}

这是我的模型

public function get_clients($p_id,$limit,$offset)
{

$this->db->select('client.*','category.id');
$this->db->join('category','category.id=client.category_id');
$this->db->order_by('client.id','desc');
$this->db->where('category.id',$p_id);
$query = $this->db->get('client',$limit,$offset);
return $query->result();
}

这是我的表名 client

id  image                        category_id
1 ["upld-file1460797715.jpg"] 6
2 ["upld-file1460797733.jpg"] 6
3 ["upld-file1460797831.jpg"] 6
4 ["upld-file1460797847.jpg"] 6
5 ["upld-file1460797864.jpg"] 6
6 ["upld-file1460797882.jpg"] 6
7 null 6
8 null 6
9 null 6
10 null 6

我的连接表名称类别如下所示

id  category_name   parent_id
6 builders 4
4 client 0
7 hospitals 4
8 municipalties 4

这里面临的问题是所有数据都显示在这里,我不需要,我只需要有要显示的图像。如果限制被删除,我会获取所有图像,但我也想使用限制

最佳答案

在模型中尝试此代码

public function get_clients($p_id,$limit,$offset)
{

$this->db->select('client.*','category.id');
$this->db->join('category','category.id=client.category_id');
$this->db->order_by('client.id','desc');
$this->db->where('category.id',$p_id);
$this->db->where('client.image !=', 'NULL');
$query = $this->db->get('client',$limit,$offset);
return $query->result();
}

关于php - 仅显示包含项目列表中的图像的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36663770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com