|
本帖最后由 liaomars 于 2011-3-9 00:04 编辑
我是从栏目发送参数到控制器,现在在问题是.分页也是读的url的第三部分,我的参数传递也是第三部分,现在冲突了.怎么调整这个uri.现在只有一个栏目可以分页.后面的栏目全报错.麻烦各位帮忙看下错在哪里,我已截图
---------------------------------------分隔线-----------------------------------------------------------
下面是我的控制器里的一段相关代码
PHP复制代码 function message ($cate) {
$this->load->Model('admin/Admin_model');
$this->load->library('Showpage');
$data['head'] = 'head';
$data['foot'] = 'foot';
$data['right'] = 'right';
$data['r_1'] = $this->right_m(2, 17);
$data['r_2'] = $this->right_m(3, 17);
$pagesize = 20;
$total = $this->db->count_all('deal where deal_cate='.$cate );
echo $cate;
$page = $this->uri->segment(3);
if (!$page) {
$page = 1;
}
$this->showpage->showPage($total, $pagesize);
$start = $this->showpage->getStart();
$sql = "SELECT * FROM deal WHERE deal_cate= $cate LIMIT ?,? ;";
$data['result'] = $this->db->query($sql, array($start, $pagesize));
$data['page'] = $this->showpage->getContent();
$this->load->view('message_list', $data);
} 复制代码
----------------------------------------------------------------------------------------------------------
下面是视图的代码
HTML复制代码 <dl>
<dt><?php
$rs = $result->row_array();
switch ($rs['deal_cate']) {
case 1:
echo "政府物业";
break;
case 2:
echo "店铺写字楼";
break;
case 3:
echo "家居房产";
break;
case 4:
echo "交通工具";
break;
case 5:
echo "电脑设备";
break;
case 6:
echo "通讯器材";
break;
case 7:
echo "家用电器";
break;
case 8:
echo "求职招聘";
break;
case 9:
echo "商业用途";
break;
case 10:
echo "其它商品";
break;
}
?> </dt>
<?php
foreach ($result->result_array() as $rs) {
?>
<dd><a href="index.php/Huanshou/message_view/<?php echo $rs['id']; ?>"> <?php echo $rs['deal_title']; ?></a></dd>
<?php
}
?>
</dl>
<div class="pagelist">
<?php echo $page; ?>
</div> 复制代码
-----------------分隔线----------------------------------
这是分页类的代码
PHP复制代码 <?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
Class Showpage {
public $page;
public $start;
public $pagesize;
public function showPage ($total=12, $pagesize=9) {
$this->pagesize = $pagesize;
$str = '';
//echo $_SERVER['PHP_SELF'];
preg_match("/index.php\/.*?\/(.*?)\/(\d.*)/", $_SERVER['PHP_SELF'], $tt);
print_r($tt);
if ($tt) {
$this->page = $tt[2];
} else {
preg_match("/index.php\/.*?\/(.*)/", $_SERVER['PHP_SELF'], $fs);
print_r($fs);
if ($fs)
$str = '';
$this->page = 1;
}
//echo $str."<br>";
$endpage = ceil($total / $this->pagesize);
$page = min($endpage, $this->page);
$mod = $total % $this->pagesize;
$prev = ($this->page - 1 <= 0 ? 1 : $this->page - 1);
$next = ($this->page == $endpage ? $endpage : $this->page + 1);
$page_end = ($this->page > $endpage ? 0 : $endpage);
if ($this->page == 1 || $endpage == 1 || $endpage == 0) {
$Index = "第一页";
$Back = "上一页";
} else {
$Index = "<a href='index.php/Yumaoqiu/huodong/1'>第一页</a>";
$Back = "<a href=index.php/Yumaoqiu/huodong/".$str.$prev.">上一页</a>";
}
if ($next == $this->page || $endpage == 1 || $endpage == 0) {
$Forward = "下一页";
} else {
$Forward = "<a href=index.php/Yumaoqiu/huodong/" . $str . $next . ">下一页</a>";
}
if ($page_end == $this->page || $endpage == 1) {
$End = "最后一页";
} else {
$End = "<a href=index.php/Yumaoqiu/".$str.$page_end.">最后一页</a>";
}
$result_contents = "<b><div id=\"contents_page\">(共" . $endpage . "页/共" . $total . "条记录):{$Index} {$Back} {$Forward} {$End}\n";
$result_contents.=" 跳转到第 <select name=\"topage\" size=\"1\" onChange=\"window.location.href =this.options[this.selectedIndex].value;\" >\n";
for ($i = 1; $i <= $endpage; $i++) {
if ($i == $this->page) {
$result_contents.="<option value='$str$i' selected>$i</option>\n";
} else {
$result_contents.="<option value='$str$i'>$i</option>\n";
}
}
$result_contents.="</select></div></b>";
$start_datum = ($this->page <= 0 ? 1 : $this->page);
$this->start = ($start_datum - 1) * $this->pagesize;
if ($this->start == "" || $this->start < 0) {
$this->start = 0;
}
$this->content = $result_contents;
}
function getStart () {
return $this->start;
}
function getContent () {
return $this->content;
}
}
?> 复制代码 |
-
|