0

我的一些代码。

$files = glob("pardod/*.html");
$record_count  = 5;
$total_pages   = ceil(count($files)/$record_count);
$page          = $_GET['page'];
$offset        = ($page-1)*$record_count;
$files_filter  = array_slice($files, $offset,$record_count);

for ($i = 0; $i<$filecount; $i++){
    if ($page){
        $start = ($page - 1) * $record_count;
    }else{
        $start = 0;
    }
}

if($total_pages > 1){
   if($page != 1){
      echo '<a href="pardod.php?page='.($page-1).'">Atpakal</a>';
   }
   if($page != $total_pages){
      echo '<a href="pardod.php?page='.($page+1).'">Uz priekšu</a>';
   }
}

php分页不起作用,我只是在学习如何制作,哪里有问题?

*.html files没有显示:(

4

3 回答 3

0

试试这个代码进行分页

  <?php

  $con=mysql_connect("localhost","root","");

  $page=$_REQUEST['page'];

  if ($page < 1)
  {
  $page = 1;
  }
  $resultsPerPage =15;
  $startResults = ($page - 1) * $resultsPerPage;
  $numberOfRows = mysql_num_rows(mysql_query('SELECT * FROM tablename'));
  $totalPages = ceil($numberOfRows / $resultsPerPage);
  echo"<center><table border='1' bordercolor='blue' height='90%' width='90%'> <tr><th     bgcolor='silver'>Name</th><th bgcolor='silver'>Password</th><th      bgcolor='silver'>Question</th><th bgcolor='silver'> Answer</th><th        bgcolor='silver'>Image</th> </tr>";

$i=1;
                                                                                  $result= mysql_query("SELECT * FROM password LIMIT   $startResults,        $resultsPerPage");

 while($row=mysql_fetch_array($result))
       {

   }

   echo"</tr></table></center>";

      echo '<center><a href="?page=1">First</a>&nbsp';

  if($page > 1)
  echo '<a href="?page='.($page - 1).'">Back</a>&nbsp';

  for($i = 1; $i <= $totalPages; $i++)
      {
if($i == $page)
  echo '<strong>'.$i.'</strong>&nbsp';
 else
   echo '<a href="?page='.$i.'">'.$i.'</a>&nbsp';
     }

  if ($page < $totalPages)
  echo '<a href="?page='.($page + 1).'">Next</a>&nbsp;';

   echo '<a href="?page='.$totalPages.'">Last</a></center>';
 ?>
于 2013-06-13T07:35:54.667 回答
0

如果您使用的是引导程序,则可以使用以下

function pagination($page, $count) {
        global $options;
        $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
        $actual_link = trim(str_replace("page=".$page, "", $actual_link), "&");

        $lenght = ceil($count/$options->get("result_per_page"));
        if ($page <= 3) {
            if ($lenght < 5) {
                $first = 0;
                $last = $lenght-1;
            } else {
                $first = 0;
                $last = 4;
            }
        } else if ($page < ($lenght-2)) {
            $first = $page-2;
            $last = $page+2;
        } else if ($page <= $lenght) {
            $first = $page-5;
            $last = $lenght-1;
        }
        if ($page > 0) {
            $prev = $page-1;
            $next = $page+1;
        } else {
            $prev = 0;
            $next = $page+1;
        }

        echo '<span>Viewing page '.($page+1).' of '.$lenght.'</span><br>';
        echo '<nav aria-label="Page navigation example">';
        echo '<ul class="pagination justify-content-center">';
        if ($prev > 0) {
            echo '<li class="page-item"><a class="page-link" href="'.$actual_link.'&page=0">&laquo;&laquo;</a></li>';
            echo '<li class="page-item"><a class="page-link" href="'.$actual_link.'&page='.$prev.'">&laquo;</a></li>';
        }
        for ($i = $first; $i<=$last; $i++) {
            if ($i == $page) {
                $active = ' active';
            } else {
                $active = '';
            }
            echo '<li class="page-item'.$active.'"><a class="page-link" href="'.$actual_link.'&page='.$i.'">'.($i+1).'</a></li>';
        }
        if ($next < $last) {
            echo '<li class="page-item"><a class="page-link" href="'.$actual_link.'&page='.$next.'">&raquo;</a></li>';
            echo '<li class="page-item"><a class="page-link" href="'.$actual_link.'&page='.($lenght-1).'">&raquo;&raquo;</a></li>';
        }
        echo '</ul>';
        echo '</nav>';
    }

调用函数

$pageNumber = 1;
$totalRowCount = 5000;
pagination($pageNumber, $totalRowCount);
于 2019-07-02T14:36:30.483 回答
0

试试这个代码

$limit = ( isset($_GET['limit'])) ? $_GET['limit'] : 5;
if (strtolower($limit) == 'all') {
    $limit = 'all';
} else {
    $limit = filter_var($limit, FILTER_SANITIZE_NUMBER_INT);
    if (trim($limit) == '') {
        $limit = 5;
    }
}

$page = ( isset($_GET['page'])) ? $_GET['page'] : 1;
$page = filter_var($page, FILTER_SANITIZE_NUMBER_INT);

$links = ( isset($_GET['links'])) ? $_GET['links'] : 1;
$links = filter_var($links, FILTER_SANITIZE_NUMBER_INT);

这是一步一步详细描述所有过程的链接。

通过学习 Ocean Team 的 PHP 简单分页

于 2018-05-28T15:24:44.430 回答