php分页,出错了

时间:2013-06-13 07:30:58

标签: php html pagination filesystems

我的一些代码。

$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未显示:(

3 个答案:

答案 0 :(得分: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>';
 ?>

答案 1 :(得分: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);

以下是逐步详细描述所有流程的链接。

Simple Pagination in PHP By Learning Ocean Team

答案 2 :(得分:0)

如果您正在使用引导程序,则可以使用以下

constructor(private host: ElementRef) {
}

get element() {
    return this.host.nativeElement;
}

private editModeHandler() {
     const clickOutside$ = fromEvent(document, 'click').pipe(
        filter(({ target }) => {
        console.log('parent', this.element, 'child', target)

          const ans = this.element.contains(target) === false
          console.log(ans)
          return  ans
        }),
        take(1)
     )
}

调用该函数

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>';
    }