ѡ̳

标题: 20190419 修复一个上一页下一页在指定排序时的错误。 [打印本页]

作者: admin    时间: 2019-4-19 14:48
标题: 20190419 修复一个上一页下一页在指定排序时的错误。
  1. //下一页
  2.                 $next_page = $this->db->get_one("`catid` = '$catid' AND `id`<'$id' AND `status`=99",'*','listorder DESC, id DESC');

  3.                 // 上一页下一页新的写法  开始2019 0419

  4.         //超找附近的数据

  5.         $around_data_1 =$this->db->select("`catid`= '$catid' AND `listorder`>'$listorder' and id!='$id'   AND `status`=99",'*',1,'listorder ASC,id ASC');
  6.         $around_data_2 = $this->db->select("`catid`= '$catid' AND `listorder`<'$listorder'   AND `status`=99",'*',1,'listorder DESC, id DESC');
  7.         $around_data_3 = $this->db->select("`catid`= '$catid' AND `id`>='$id' AND `listorder`>='$listorder' AND `status`=99",'*',2, 'listorder ASC,id ASC');
  8.         $around_data_4 = $this->db->select("`catid`= '$catid' AND `id`<'$id' AND `listorder`<='$listorder'   AND `status`=99",'*',1, 'listorder DESC, id DESC');

  9.         $around_data_a = array_merge((array)$around_data_1,(array)$around_data_2);
  10.         $around_data_b = array_merge((array)$around_data_3,(array)$around_data_4);
  11.         $around_data = array_merge($around_data_a,$around_data_b);
  12.         //将数组 按照先listorder  后 ID  降序排
  13.         foreach ($around_data as $key => $row) {
  14.             $around_data_volume[$key]  = $row['listorder'];
  15.             $around_data_edition[$key] = $row['id'];
  16.          }

  17.          array_multisort($around_data_volume, SORT_DESC, $around_data_edition, SORT_DESC, $around_data);
  18.          // print_r($around_data);

  19.          $current_pos = array_search($id, array_column($around_data, 'id'));

  20.          $previous_page = $around_data[$current_pos-1];

  21.          $next_page =     $around_data[$current_pos+1];

  22.          //上一页下一页新的写法  结束  2019 0419
复制代码

phpcms\modules\content\index.php
  1. //内容页
  2.         public function show() {
复制代码


作者: admin    时间: 2019-4-22 10:44
新增按发布时间的上一页下一页
  1. // 上一页下一页新的写法  开始2019 0419

  2.         //超找附近的数据

  3.         $around_data_1 =$this->db->select("`catid`= '$catid' AND `listorder`>'$listorder' and id!='$id'   AND `status`=99",'*',1,'listorder ASC,inputtime ASC');
  4.         $around_data_2 = $this->db->select("`catid`= '$catid' AND `listorder`<'$listorder'   AND `status`=99",'*',1,'listorder DESC, inputtime DESC');
  5.         $around_data_3 = $this->db->select("`catid`= '$catid' AND `inputtime`>='".strtotime($inputtime)."' AND `listorder`>='$listorder' AND `status`=99",'*',2, 'listorder ASC,inputtime ASC');
  6.         $around_data_4 = $this->db->select("`catid`= '$catid' AND `inputtime`<'".strtotime($inputtime)."' AND `listorder`<='$listorder'   AND `status`=99",'*',1, 'listorder DESC, inputtime DESC');

  7.         $around_data_a = array_merge((array)$around_data_1,(array)$around_data_2);
  8.         $around_data_b = array_merge((array)$around_data_3,(array)$around_data_4);
  9.         $around_data = array_merge($around_data_a,$around_data_b);
  10.         //将数组 按照先listorder  后 ID  降序排
  11.         foreach ($around_data as $key => $row) {
  12.             $around_data_volume[$key]  = $row['listorder'];
  13.             $around_data_edition[$key] = $row['inputtime'];
  14.          }

  15.          array_multisort($around_data_volume, SORT_DESC, $around_data_edition, SORT_DESC, $around_data);
  16.           //print_r($around_data);

  17.          $current_pos = array_search(strtotime($inputtime), i_array_column($around_data, 'inputtime'));

  18.          $previous_page = $around_data[$current_pos-1];

  19.          $next_page =     $around_data[$current_pos+1];

  20.          //上一页下一页新的写法  结束  2019 0419
复制代码





欢迎光临 ѡ̳ (http://www.sunminxuan.cn/bbs/) Powered by Discuz! X3.4