//get all the data of both table
foreach($tables as $table){
$table_history = $table.'_history';
$result[] = DB::table($table)->join($table_history, $table.user_id, '=',$table_history.user_id )->paginate(5);
}
当我尝试
时<?php echo $result->links(); ?>
它没有任何回报。
还尝试print_r结果
<?php print_r($result); ?>
它返回了:
Illuminate\Pagination\Paginator Object ( [factory:protected] => Illuminate\Pagination\Factory Object ( [request:protected] => Illuminate\Http\Request Object ( [json:protected] => [sessionStore:protected] => [attributes] => Symfony\Component\HttpFoundation\ParameterBag Object ( [parameters:protected] => Array ( ) ) [request] => Symfony\Component\HttpFoundation\ParameterBag Object ( [parameters:protected] => Array ( ) ) [query] => Symfony\Component\HttpFoundation\ParameterBag Object ( [parameters:protected] => Array ( ) ) [server] => Symfony\Component\HttpFoundation\ServerBag Object ( [parameters:protected] => Array ( [DOCUMENT_ROOT] => C:\xampp\htdocs\system101\public [REMOTE_ADDR] => ::1 [REMOTE_PORT] => 53241 [SERVER_SOFTWARE] => PHP 5.4.7 Development Server [SERVER_PROTOCOL]
我尝试将变量变成数组:
$result[] = DB::table('user')->join('position', user.user_id, '=',position.user_id )->get();
显示所需的所有数据。但是,我确实将其更改为->paginate(5)
它像上面那样返回。
如何显示分页链接?或者还有其他方式如何进行分页?
答案 0 :(得分:1)
加入仅采用字符串参数
Laravel连接语法
join(string $table, string $one, string $operator = null, string $two = null, string $type = 'inner', bool $where = false)
修复查询中的数据库属性字符串
$result = DB::table('user')
->join('position', 'user.user_id', '=', 'position.user_id')->paginate(5);
<强>此外... 强>
foreach($tables as $table):
$table_history = $table.'_history';
$result = DB::table($table)
->join("$table_history", "$table.user_id", '=', "$table_history.user_id")
->paginate(5);
endforeach;