【问题标题】:PHP pagination by tag [closed]PHP按标签分页[关闭]
【发布时间】:2013-11-08 17:43:34
【问题描述】:

我有一个带有大文本的数据库字段。如果<!-- new page --> 中有标签,我想按该标签进行分页。

我想做的是像 WordPress 那样,当你插入一个标签,比如 <!-- new page --> 我想创建一个新页面。

假设我有这个来自数据库的文本

Lorem ipsum dolor sit amet,consectetur adipiscing elit。 Quisque elementum magna in nulla ultrices,eu pulvinar nulla auctor。 Praesent auctor ut dui vitae feugiat。

<!-- new page -->

Sed risus nisl, tristique sed tristique et, auctor eu augue。在 hac habitasse platea dictumst 中。融合 ipsum ligula。 Aliquam 前庭 ligula ut ligula porta gravida。 Curabitur tincidunt a est vitae eleifend。 Duis ullamcorper nunc sapien, quis molestie tellus ornare vel。努拉姆在米埃罗斯。

如何让第二段出现在新页面上?

类似http://en.support.wordpress.com/splitting-content/nextpage/

【问题讨论】:

  • 也许你需要学会更清楚地提问才能得到答案
  • 抱歉,我不太清楚如何措辞。我已经更新了我的问题,希望这更有意义
  • 这个问题表明没有尝试研究或解决问题。请阅读有关提问的帮助部分:stackoverflow.com/help/on-topic

标签: php pagination


【解决方案1】:

我希望我的代码会有所帮助:

<?php
//in this example :
//first you have to create a database with name : blog
// create table : article (id as primary key, name , content)
// here we supposed that in the content you have your tags <!-- new page -->
// also i supposed the name of this file as : pagination.php

//Getting the id of article:
//=========================
if(isset($_GET['id']))
    $id_article = $_GET['id'];
else
    $id_article = 1;



//Connexion to database :
//======================
$user="root";
$pass="root";
$db="blog";
$host="localhost";

$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host='.$host.';dbname='.$db, $user, $pass, $pdo_options);
$bdd->query("SET NAMES 'utf8'");


$response = $bdd->query('SELECT * FROM articles WHERE id='.$id_article);

$tab_content = array();

$data = $response->fetch()
echo'<div >';
    $tab_content = explode('<!-- new page -->',$data['content']);
    $count_pages = count($tab_content);
    if($count_pages){
            //in the case that you have somme tags :
            //=====================================
        echo $tab_content[$page];
        echo '<br>';
        for($i=1;$i<$count_pages;$i++)
            echo '<a href="./pagination.php?id='.$id_article.'&page='.$i.'">'.$i.'</a>&nbsp;&nbsp;';
    }
    else{
            //if no tags '<!-- new page -->' in your content:
            //===============================================
        echo $data['content'];
    }
echo '</div>';

$response->closeCursor();

?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-31
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 2016-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多