這篇文章給大家介紹使用thinkPHP怎么實(shí)現(xiàn)一個(gè)多表查詢和分頁功能,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

// 異步請(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();
// 總頁數(shù)
$regNum = ceil($count/6);
// 驗(yàn)證當(dāng)前請(qǐng)求頁碼是否大于總頁數(shù)
$page = $page > $regNum ? $regNum : $page;
// 引入ajax分頁庫(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, '<font color=\'red\'>' . $vv . '</font>', $value['re_title']);
}
if (strpos($value['rta_title'], $vv) !== FALSE) {
$value['rta_title'] = str_replace($vv, '<font color=\'red\'>' . $vv . '</font>', $value['rta_title']);
}
}
}
$value['re_created'] = date('Y-m-d', $value['re_created']);
}
echo json_encode($list);
}關(guān)于使用thinkPHP怎么實(shí)現(xiàn)一個(gè)多表查詢和分頁功能就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
名稱欄目:使用thinkPHP怎么實(shí)現(xiàn)一個(gè)多表查詢和分頁功能-創(chuàng)新互聯(lián)
分享網(wǎng)址:http://chinadenli.net/article2/cdojoc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、商城網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈、網(wǎng)站策劃、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容