dsigg21445 2015-07-28 23:57
浏览 79
已采纳

PHP每页新闻5 /分页下一页 - 上一页

Is possibile to create PHP pagination system?

With next - prev pagination link? Max 5 news per page.

This is my php code:

<?php
include('config.php');

$query1=mysql_query("select id, name, email , age from addd");
echo "<table><tr><td>Testo</td><td>Nome</td><td>Anni</td></tr>";

function truncate_string($str, $length) {
if (!(strlen($query2['name']) <= $length)) {
$query2['name'] = substr($query2['name'], 0, strpos($query2['name'], '        ', $length)) . '...';
}

return $query2['name'];
}

while($query2=mysql_fetch_array($query1))
{
$number= $query2['name'];
echo "<tr><td>".substr($query2['name'], 0, 500).".....</td>";
echo "<td>".$query2['email']."</td>";
echo "<td>".$query2['age']."</td>";
echo "<td>".str_word_count($number)."</td>";
echo "<td><a href='edit.php?id=".$query2['id']."'>Mod</a></td>";
echo "<td><a href='delete.php?id=".$query2['id']."' onclick=\"return     confirm('Sei sicuro di volerlo eliminare?');\");'>Canc</a></td><tr>";
echo "<td><a href='singletwo.php?id=".$query2['id']."');'>vedi</a></td><     tr>"; }?>

I tried it in different ways , but I failed. I read other answers , but I have been of help.

  • 写回答

1条回答 默认 最新

  • doumi1884 2015-07-29 00:16
    关注

    You can do most of it in your query, for example:

    if( isset( $_GET["page"]) ) $PAGE=$_GET["page"]; else $PAGE=1;
    $query1=mysqli_query($db,"select id, name, email , age from add LIMIT ". ($PAGE * 5) - 5) .",5");
    

    this will give you pagination. You can then point next and previous links to ?page=n (where n is the next page number).

    Hope this helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序