在分页数之间添加点 [英] Adding dots between numbers of pagination

查看:54
本文介绍了在分页数之间添加点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 PHP 和 AJAX 为表格编写了分页代码.在每个页面中,它将显示表格的 8 行.到这里为止都可以正常工作.

我现在需要的是让分页看起来像一系列数字和它们之间的点,就像这样(1 2 3 .... 27 28 29).

我有这两个分页文件:

conf.php

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><link rel="stylesheet" id="font-awesome-style-css"href="http://phpflow.com/code/css/bootstrap3.min.css" type="text/css"媒体=所有"><script type="text/javascript" charset="utf8"src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"><身体><div><p>表 <br/></p><div id="target" >正在加载...</div><?php包括('dbconnect.php');$limit = 8;$sql = "选择 * 从地点";$rs_result = mysqli_query($connect,$sql);$c = mysqli_num_rows($rs_result);//计算行数$total_num_pages = ceil($c/$limit);?><div align="center"><ul class='pagination text-center' id="pagination"><?phpif(!empty($total_num_pages)):for($j=1; $j<=$total_num_pages; $j++):if($j == 1):?><li class='active' id="<?php echo $j;?>"><a href='paginate.php?page=<?php echo $j;?>'><?php echo $j;?></a><?php 其他:?><li id="<?php echo $j;?>"><a href='paginate.php?page=<?php echo $j;?>'><?php echo $j;?></a><?php endif;?><?php endfor;endif;?>

<脚本>jQuery(文档).准备好(函数(){jQuery("#target").load("paginate.php?page=1");jQuery("#pagination li").live('click',function(e){e.preventDefault();jQuery("#target").html('加载中...');jQuery("#pagination li").removeClass('active');jQuery(this).addClass('active');var pageNum = this.id;jQuery("#target").load("paginate.php?page=" + pageNum);});});

第二个是paginate.php:

<?phpecho '<p style="color:#003566;font-size:15px;">&nbsp;您在页面 '.$page.'
</p>';echo '';echo '<tr><th>姓名</th><th>link</th><th>我的日期</th><th>结束日期</th><th>place</th><th>/th></tr>';while ($row = mysqli_fetch_assoc($result)) {echo "<tr><td>";回声 $row['name'];echo "</td><td>";回声 $row['link'];echo "</td><td>";回声 $row['date'];echo "</td><td>";回声 $row['end'];echo "</td><td>";回声 $row['place'];echo "</td></tr>";}echo '</table>';?>

谁能告诉我这样做的方法吗?

解决方案

也请查看此链接

I have written a code for pagination in PHP and AJAX for a table. In each page it will show 8 rows of the table. It works fine until here.

What I need now is to make the pagination looks like series of numbers and dots between them like this (1 2 3 .... 27 28 29).

I have this two files for the pagination:

conf.php

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" id="font-awesome-style-css"
        href="http://phpflow.com/code/css/bootstrap3.min.css" type="text/css" 
        media="all">
    <script type="text/javascript" charset="utf8"
         src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js">
    </script>
</head>

<body>

    <div>
        <p> Table <br/> </p>
        <div id="target" >Loading ...</div>

        <?php
            include('dbconnect.php'); 
            $limit = 8;
            $sql = "SELECT * FROM places";  
            $rs_result = mysqli_query($connect,$sql);   
            $c = mysqli_num_rows($rs_result); //count number of rows
            $total_num_pages = ceil($c / $limit); 
        ?>

        <div align="center">
            <ul class='pagination text-center' id="pagination">
            <?php 
            if(!empty($total_num_pages)):for($j=1; $j<=$total_num_pages; $j++):
                if($j == 1):?>
                    <li class='active' id="<?php echo $j;?>">
                        <a href='paginate.php?page=<?php echo $j;?> '><?php echo $j;?></a>
                    </li> 
                <?php else:?>
                    <li id="<?php echo $j;?>">
                        <a href='paginate.php?page=<?php echo $j;?>'><?php echo $j;?></a>
                    </li>
                <?php endif;?>          
            <?php endfor;endif;?>
            </ul>  
        </div>
    </div>
    <script>
        jQuery(document).ready(function() {
        jQuery("#target").load("paginate.php?page=1");
            jQuery("#pagination li").live('click',function(e){
            e.preventDefault();
                jQuery("#target").html('loading...');
                jQuery("#pagination li").removeClass('active');
                jQuery(this).addClass('active');
                var pageNum = this.id;
                jQuery("#target").load("paginate.php?page=" + pageNum);
            });
            });
    </script>
</body>

The second is paginate.php:

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

    $limit = 8;  
    if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };  
    $start_from = ($page-1) * $limit;  

    $query = "SELECT * FROM places ORDER BY id ASC LIMIT $start_from, $limit";  
    $result = mysqli_query($connect,$query); 

    if(!$query)
    {
        echo mysql_error();
    }
?>

<?php 
    echo '<p style="color:#003566;font-size:15px;">  &nbsp; You are on page ' .$page. '<br> </p>';
    echo '<table border="1" align="center">';

    echo '<tr><th>Name</th><th>link</th><th>My date</th><th>End date</th><th>place</th></tr>';

    while ($row = mysqli_fetch_assoc($result)) { 
        echo "<tr><td>";
        echo $row['name']; 
        echo "</td><td>";
        echo $row['link']; 
        echo "</td><td>";   
        echo $row['date'];
        echo "</td><td>";
        echo $row['end']; 
        echo "</td><td>";   
        echo $row['place'];
        echo "</td></tr>";   
    }
    echo '</table>';
?>

Can anyone show me the way to do that?

解决方案

<?php
$numbers = array(1,2,3,4,5,6,7,8,9,10,11,12);
$output = '';
$counter = 1;
foreach ($numbers as $number){
    if($counter == 4){
        $output .= ' ...';
    }elseif($counter < 4 || $counter > (count($numbers) -3)){
        $output .= ' ' . $number;
    }
    $counter++;
}

Check this link also

这篇关于在分页数之间添加点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆