Php Codeigniter:如何向策划的分页结果添加href链接

Php Codeigniter:如何向策划的分页结果添加href链接,php,codeigniter,pagination,hyperlink,anchor,Php,Codeigniter,Pagination,Hyperlink,Anchor,我已经用CodeIgniter进行了分页,它将我数据库中的结果列为、标题、内容、价格和postid。我想知道如何使它显示的内容(标题、内容、价格)显示为链接( function index() { $this->load->library('pagination'); $this->load->library('table'); $this->table->set_headin

我已经用CodeIgniter进行了分页,它将我数据库中的结果列为、标题、内容、价格和postid。我想知道如何使它显示的内容(标题、内容、价格)显示为链接(
function index() 
    {
            $this->load->library('pagination');
            $this->load->library('table');

            $this->table->set_heading('postid', 'The Title', 'The Content', 'Price');

            $config['base_url'] = 'http://localhost/ganbaru/index.php/site/index';
            $config['total_rows'] = $this->db->get('posts')->num_rows();
            $config['per_page'] = 10;
            $config['num_links'] = 20;
            $config['full_tag_open'] = '<div id="pagination">';
            $config['full_tag_close'] = '</div>';

            $this->pagination->initialize($config);

            $posts['records'] = $this->db->get('posts', $config['per_page'], $this->uri->segment(3));

            $this->load->view('site_view', $posts);
    }
函数索引()
{
$this->load->library('pagination');
$this->load->library('table');
$this->table->set_heading('posted','Title','Content','Price');
$config['base_url']='http://localhost/ganbaru/index.php/site/index';
$config['total_rows']=$this->db->get('posts')->num_rows();
$config['per_page']=10;
$config['num_links']=20;
$config['full_tag_open']='';
$config['full_tag_close']='';
$this->pagination->initialize($config);
$posts['records']=$this->db->get('posts',$config['per_page'],$this->uri->segment(3));
$this->load->view('site_view',$posts);
}
这是查看代码

</head>
<body>  


<div id="container">
                    <h1>Super Pagination with CodeIgniter</h1>
                    <?php echo $this->table->generate($records); ?>
                    <?php echo $this->pagination->create_links(); ?>
            </div>
</body>
</html>

使用CodeIgniter进行超级分页

抱歉,我不太明白

我没有使用表库,但您可以创建循环,并使用以下方法输出链接:

在控制器中:

$query = $this->db->get('posts', $config['per_page'], $this->uri->segment(3));
$posts["records"] = $query->result_array();
在视图文件中:

</head>
<body>  
<div id="container">
<h1>Super Pagination with CodeIgniter</h1>
<table>
<?php foreach($records as $record) { ?>
<tr>
<td><a href="<?php echo site_url('myuri/' . $record["id"]); ?>"><?php echo $record["id"]; ?></a></td>
<td><a href="<?php echo site_url('myuri/' . $record["id"]); ?>"><?php echo $record["title"]; ?></a></td>
<td><a href="<?php echo site_url('myuri/' . $record["id"]); ?>"><?php echo $record["content"]; ?></a></td>
</tr>
<?php } ?>
</table>
<?php echo $this->pagination->create_links(); ?>
</div>
</body>
</html>
它产生了:

<strong>1</strong>
<a href="http://example.com/index.php/test/page/20">2</a>
<a href="http://example.com/index.php/test/page/40">3</a>
<a href="http://example.com/index.php/test/page/20">&gt;</a>
<a href="http://example.com/index.php/test/page/180">Last &rsaquo;</a>
1
它确实有标签。因此,您应该看看《用户指南》中的示例,并可能将分页输出作为变量存储在
posts
下,以便您可以在页面上显示它。例如
$posts[“Pagination”]=$this->Pagination->create_links();
然后使用
echo$pagination
将其显示在页面上

文档位于-,因此您可以快速阅读所有选项


希望对…有所帮助。

更新对不起,我不太明白

我没有使用表库,但您可以创建循环,并使用以下方法输出链接:

在控制器中:

$query = $this->db->get('posts', $config['per_page'], $this->uri->segment(3));
$posts["records"] = $query->result_array();
在视图文件中:

</head>
<body>  
<div id="container">
<h1>Super Pagination with CodeIgniter</h1>
<table>
<?php foreach($records as $record) { ?>
<tr>
<td><a href="<?php echo site_url('myuri/' . $record["id"]); ?>"><?php echo $record["id"]; ?></a></td>
<td><a href="<?php echo site_url('myuri/' . $record["id"]); ?>"><?php echo $record["title"]; ?></a></td>
<td><a href="<?php echo site_url('myuri/' . $record["id"]); ?>"><?php echo $record["content"]; ?></a></td>
</tr>
<?php } ?>
</table>
<?php echo $this->pagination->create_links(); ?>
</div>
</body>
</html>
它产生了:

<strong>1</strong>
<a href="http://example.com/index.php/test/page/20">2</a>
<a href="http://example.com/index.php/test/page/40">3</a>
<a href="http://example.com/index.php/test/page/20">&gt;</a>
<a href="http://example.com/index.php/test/page/180">Last &rsaquo;</a>
1
它确实有标签。因此,您应该看看《用户指南》中的示例,并可能将分页输出作为变量存储在
posts
下,以便您可以在页面上显示它。例如
$posts[“Pagination”]=$this->Pagination->create_links();
然后使用
echo$pagination
将其显示在页面上

文档位于-,因此您可以快速阅读所有选项

希望这对……有所帮助。

该软件的功能非常有限

您可以通过以下方式实现您想要的:

$table_heading = array(
                       '<a href="some_link">Title</a>', 
                       '<a href="some_link/foo">Price</a>');

$this->table->set_heading($table_heading);
$table\u heading=数组(
'', 
'');
$this->table->set_heading($table_heading);
这将使您直接控制标题行中的任何内容。这是未经测试的,但应该有效

Johann建议的另一个选项是手动创建表,这当然会让您100%地控制输出。

它的功能非常有限

您可以通过以下方式实现您想要的:

$table_heading = array(
                       '<a href="some_link">Title</a>', 
                       '<a href="some_link/foo">Price</a>');

$this->table->set_heading($table_heading);
$table\u heading=数组(
'', 
'');
$this->table->set_heading($table_heading);
这将使您直接控制标题行中的任何内容。这是未经测试的,但应该有效


Johann建议的另一个选项是手动创建表,这当然会让您100%地控制输出。

谢谢您的回答。我想我还不够清楚,因为我对分页链接没有问题,我对它管理的数据库内容有问题。因此,标题、内容、价格等内容都很重要只是显示无法点击的文本。我希望这有助于我非常感谢你的帮助哇,非常感谢!我非常感谢你花时间这么做,如果没有你,我不可能这么快就解决这个问题!谢谢你的回复。我想我不够清楚,因为我对分页链接没有问题,我是h避免了它正在管理的数据库内容的麻烦。因此,标题、内容、价格等内容只是显示无法单击的文本。我希望这有助于我非常感谢你的帮助哇,非常感谢!我非常感谢你花时间做这件事,如果没有你,我不可能这么快就解决这个问题!谢谢你的帖子!我喜欢约翰的回答,因为它能让我灵活地控制桌子的各个方面。我很感激:)谢谢你的帖子!我喜欢约翰的回答,因为它能让我灵活地真正控制桌子的各个方面。我很感激:)