這篇文章給大家介紹使用thinkPHP怎么實(shí)現(xiàn)一個(gè)多表查詢(xún)和分頁(yè)功能,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
創(chuàng)新互聯(lián)主營(yíng)圖們網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,app軟件開(kāi)發(fā)公司,圖們h5小程序開(kāi)發(fā)搭建,圖們網(wǎng)站營(yíng)銷(xiāo)推廣歡迎圖們等地區(qū)企業(yè)咨詢(xún)// 異步請(qǐng)求試卷夾下某一個(gè)試卷夾的列表 public function ajaxLists() { extract($_GET); $page = intval($_GET['p']); $prefix = C('DB_PREFIX'); $collect = $prefix . 'collect'; $resource = $prefix . 'resource'; if ($keyword) { $arr = preg_split('/ /', $keyword); // 搜索標(biāo)簽 foreach ($arr as $value) { $id = A('Home/Papers')->trunWordToId(array($value)); if ($id) { $where['resource.rta_id'][] = array('LIKE', '%,' . $id . ',%'); } $where['resource.re_title'][] = array('LIKE', '%' . $value . '%'); } if ($where['resource.rta_id']) { $where['resource.rta_id'][] = 'AND'; } if ($where['resource.re_title']) { $where['resource.re_title'][] = 'OR'; } if ($where['resource.re_title'] && $where['resource.rta_id']) { $where['_logic'] = 'OR'; } } if ($where) { $map['_complex'] = $where; } $map['collect.a_id'] = $this->authInfo['a_id']; $map['_string'] = 'collect.col_object_id = resource.re_id'; // 總數(shù) $count = M()->table("$collect collect, $resource resource")->where($map)->count(); // 總頁(yè)數(shù) $regNum = ceil($count/6); // 驗(yàn)證當(dāng)前請(qǐng)求頁(yè)碼是否大于總頁(yè)數(shù) $page = $page > $regNum ? $regNum : $page; // 引入ajax分頁(yè)庫(kù) import("@.ORG.Util.AjaxPage"); $Page = new AjaxPage($count, 6); $list['page'] = trim($Page->show()); $list['list'] = M()->table("$collect collect, $resource resource")->where($map)->order('col_id DESC')->limit($Page->firstRow . ',' . $Page->listRows)->field('collect.col_id,collect.col_object_id,resource.re_id,resource.re_title,resource.re_created,resource.re_collect_count,resource.re_score_count,resource.re_score_num,resource.rta_id')->select(); // 獲取試卷的標(biāo)簽 $wheree['rta_id'] = array('IN', trim(str_replace(',,', ',', implode('', getValueByField($list['list'], 'rta_id'))), ',')); $tag = setArrayByField(M('ResourceTag')->where($wheree)->field('rta_id,rta_title')->select(), 'rta_id'); // 把標(biāo)簽和試卷對(duì)應(yīng) foreach ($list['list'] as $key => &$value) { $str = ''; foreach ($tag as $k => $v) { if (strpos($value['rta_id'], ',' . $k . ',') !== FALSE) { $str .= ' | ' . $v['rta_title']; } $value['rta_title'] = trim($str, ' |'); } if ($keyword) { foreach ($arr as $vv) { if (strpos($value['re_title'], $vv) !== FALSE) { $value['re_title'] = str_replace($vv, '' . $vv . '', $value['re_title']); } if (strpos($value['rta_title'], $vv) !== FALSE) { $value['rta_title'] = str_replace($vv, '' . $vv . '', $value['rta_title']); } } } $value['re_created'] = date('Y-m-d', $value['re_created']); } echo json_encode($list); }
關(guān)于使用thinkPHP怎么實(shí)現(xiàn)一個(gè)多表查詢(xún)和分頁(yè)功能就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。