protected function tableJoin($table) {
$table = trim($table,',');
$Model = M();
if (strpos($table, ',') === false) {
return $Model->table(DB_PREFIX.$table);
} else {
$tableArray = explode(',', $table);
$resultObject = $Model->table(DB_PREFIX.$tableArray[0]);
array_shift($tableArray);
foreach ($tableArray as $tableValue) {
$tableValue = explode('|',trim($tableValue,'|'));
$resultObject = $resultObject->join(DB_PREFIX."{$tableValue[0]} ON {$tableValue[1]}");
}
return $resultObject;
}
}其中,Tab的格式如下:table="表名,联表1|联表条件,联表2|联表条件"
现在要处理联表分页查询,
$Model = $this->tableJoin($tag['table']);
$tag['order'] = isset($tag['order']) ? $tag['order'] : 'id DESC';
/* 解析过滤 */
$tag['where'] = $this->replaceVar($tag['where']);
$total = $Model->cache($tag['cache'])->where($tag['where'])->count(1);
echo $Model->getLastSql().'<br />';
$url = preg_replace('/(page[\/=].*)([\?\&\/])/U', '$2', $_SERVER['REQUEST_URI']);
$delimiter = strpos($url, '?')===false ? '?' : '&';
$Page = new Page($total,$url.$delimiter.'page={PAGE}',$tag['limit']);
$data = array();
$data['page'] = $Model->cache($tag['cache'])->field($tag['field'])->where($tag['where'])->order($tag['order'])->limit($Page->limit())->select();
echo $Model->getLastSql().'<br />';但是我通过echo $Model->getLastSql().'<br />';打应出的SQL如下:
SELECT COUNT(1) AS tp_count FROM crcms_server AS s LEFT JOIN test_game AS g ON s.game_id=g.id WHERE ( game_id=5 ) LIMIT 1
SELECT `id`,`game_id`,`ti
第二张表的表名,不见,了,奇怪问题,一直没找到答案,希望能得到高人提点下,谢谢
最佳答案