gpt4 book ai didi

php - 将图像 ID 传递给 URL 段

转载 作者:行者123 更新时间:2023-12-01 05:33:30 26 4
gpt4 key购买 nike

我试图单击图像上的下一个按钮,以从从数据库获取的结果中加载下一个图像,但加载了一个新页面,因此 Bootstrap 轮播无法按我需要的方式工作。

假设我有一张包含 3 张图片的相册。这些图像的图像 ID 为 - 25、34、36。当我查看包含所有图像的相册时,我可以单击图像 ID 34。当我单击下一步时,这将带我到 www.domain.com/image/34想要重定向到 www.domain.com/image/36,然后再次单击“下一步”将重定向到 www.domain.com/image/25

所以这是我到目前为止所拥有的:

Controller :

function index($image_id)
{
// get album data
$this->data['image_data'] = $this->album_model->get_album_image_data($image_id);

$album_id = $this->data['image_data']->album_id;
$this->data['album_images'] = $this->album_model->get_all_images($album_id);

$data = $this->data;

$this->_render_page('images/image', $data);
}

查看:

foreach($album_images as $img)
{
if($img->image_id == $this->uri->segment(2))
{
echo '<img src="'.$img->image_url.'" class="img-responsive img-panel" class="img-responsive" />';
}
}
<!-- Image nav -->
<a class="fui-arrow-left left" href="#"></a>
<a class="fui-arrow-right right" href="#"></a>

如何获取下一个和上一个 image_id?

如果我需要包含更多信息,请告诉我。

最佳答案

可以使用分页,首先加载分页库。$this->load->library('pagination');引用https://codeigniter.com/user_guide/libraries/pagination.html?highlight=pagination

Controller

public function index()
{
$config['base_url'] = site_url('dashboard-clients');
$config['total_rows'] = //total count of your image or data
$config['per_page'] = 1;

//show the number of pages
$choice = $config['total_rows']/$config['per_page'];
$config['num_link'] = round($choice);
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) :0;
$result = $this->Your_Model->get('table name',$config['per_page'], $page)
$str_links = $this->pagination->cretae_links();
$data['links'] = explode('&nbsp', $str_links);
if($result != FALSE)
{
$data['data'] = $result;
$this->load->view('yoyr view file', $data);
}
}

型号

public function get($table, $limit, $start)
{
$this->db->limit($limit, $start);
$query = $this->db->get($table);
if($query->num_rows() > 0)
{
return $query->reult();
}
else
return FALSE;
}

查看

foreach($data as $img)
{
echo '<img src="'.$img->image_url.'" class="img-responsive img-panel" class="img-responsive" />';
}
//create links like 1 ,2, 3,next
<div id="pagination" align="center">
<ul class="pagination">
<?php if (isset($links) and is_array($links)) {
foreach ($links as $link) {
echo '<li>'.$link.'</li>';
}
}?>
</ul>
</div>

关于php - 将图像 ID 传递给 URL 段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35466648/

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