Php 我将如何为这些数据分页?

Php 我将如何为这些数据分页?,php,mysql,pagination,Php,Mysql,Pagination,你会怎么给这个编页码? 数据由下面的“getInstance”查询调用,该查询将显示一些称为“pages”的记录,这些记录将在动态表中列出 我想能够显示每个查询只有10“页”和分页他们向前 <table width="100%" border="0" cellpadding="0" cellspacing="0" class="std"> <?php $counter = 1; $userID = PageD

你会怎么给这个编页码? 数据由下面的“getInstance”查询调用,该查询将显示一些称为“pages”的记录,这些记录将在动态表中列出

我想能够显示每个查询只有10“页”和分页他们向前

     <table width="100%" border="0" cellpadding="0" cellspacing="0" class="std">

        <?php   


        $counter = 1;
        $userID = PageDB::getInstance()->get_user_id_by_name($_SESSION['user']);
        $result = PageDB::getInstance()->get_pages_by_campaign_id($campaignID);
        $i=0;
            while ($row = mysqli_fetch_array($result)):
             $style = "";
                if($i%2==0)
{
    $style = ' style="background-color: #EFEFEF"';
}
echo "<tr".$style.">";
            echo "<td>&nbsp;</td>";
            echo "<td></td>";


            //The loop is left open
            ?>
            <td>
            <form style="display:none;"></form>
            <div id="Pagination" class="pagination"> </div>
    <div id="Searchresult"> </div>
                <form name="editPage" action="editPage.php" method="GET">
                    <input type="hidden" name="pageID" value="<?php echo $pageID = $row['pid']; ?>" />
                    <input type="submit" name="editPage"  value="<?php echo "Page "  . $counter; ?>" style="background:none;border:none; cursor:pointer"/>
                </form>

            </td>
            <td>
                <form name="deletePage" action="deletePage.php" method="POST">
                    <input type="hidden" name="pageID" value="<?php echo $pageID = $row['pid']?>"/>
                    <input type="submit" name="deletePage" value="Delete" onclick = "javascript: return confirm('Delete Page <?php echo $counter ?> ?');"/>
                </form>
            </td>              
            <?php
            $pageID = $row['pid'];  
            $counter++;
            $i++;

            echo "</tr>\n";
        endwhile;
        mysqli_free_result($result);
        ?>
    </table>

有人能找到解决办法吗?谢谢大家!

您可以在MySQL中使用限制查询

SELECT pid , campaignid 
FROM pages , campaigns 
WHERE campaignid = campaigns.id
LIMIT first_record_number, how_many_records
可以帮助您获取当前页码等

 $pager_options = array(
    'mode'       => 'Sliding',
    'perPage'    => 10,
    'delta'      => 2,
    'totalItems' => $total_count,
 );

 $pager = Pager::factory($pager_options);

 list($from, $to) = $pager->getOffsetByPageId();
 //TODO: get and display data from database
 //first_record_number = $from-1
 //how_many_records = 10

 //show the links
 echo $pager->links;
我的建议是使用虚拟化库与数据库进行通信,例如。有一种方法:

$rs = $conn->SelectLimit("SELECT pid , campaignid 
FROM pages , campaigns 
WHERE campaignid = campaigns.id", how_many_records,first_record_number);
$arr1 = $rs->GetArray();

它还可以过滤输入数据,以数组形式获取所有结果,以及许多其他有用的功能。

这里的关键字是查询中需要添加的
LIMIT
。谷歌上的教程太多了。试试看。如果你被卡住了,告诉我们你在哪里被卡住了。什么不起作用。等等…不幸的是,我无法将Pear或其扩展加载到所讨论的服务器上:-s此扩展不使用任何其他Pear类,因此您可以手动下载它并提取到应用程序的源代码。如有必要,在
require
中更改路径,并在
Common.php
中替换/删除
PEAR::raiseError
。谢谢,我会试一试的!
$rs = $conn->SelectLimit("SELECT pid , campaignid 
FROM pages , campaigns 
WHERE campaignid = campaigns.id", how_many_records,first_record_number);
$arr1 = $rs->GetArray();