ѡ̳

 找回密码
 ע
搜索
查看: 56|回复: 1
打印 上一主题 下一主题

20190419 修复一个上一页下一页在指定排序时的错误。

[复制链接]

789

主题

1158

帖子

4197

积分

Ա

Rank: 9Rank: 9Rank: 9

积分
4197
跳转到指定楼层
¥
发表于 2019-4-19 14:48:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  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() {
复制代码

回复

使用道具 举报

789

主题

1158

帖子

4197

积分

Ա

Rank: 9Rank: 9Rank: 9

积分
4197
ɳ
 楼主| 发表于 2019-4-22 10:44:45 | 只看该作者
新增按发布时间的上一页下一页
  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
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | ע

本版积分规则

QQ|Archiver|ֻ|С|ѡ̳

GMT+8, 2026-5-2 07:28 , Processed in 0.080441 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表
0.0957s