桌面和移动设备的PHP分页

时间:2017-04-06 11:41:42

标签: php pagination

我想为桌面设备和移动设备设计分页,条件是桌面视图我要显示最多3行在移动视图中我想显示每页最多1行我有以下分页脚本,这是为静态条件工作,但我希望它是动态的桌面和移动。请帮助我,并提前感谢。

PHP script

<html>

   <body>



         <div id="content">
            <?php
               $query1=mysql_connect("localhost","root","");
               mysql_select_db("customer_fetcher",$query1);

               $start=0;
               $limit=1;

               $id = 1;

               if(isset($_GET['id']))
               {
                   $id=$_GET['id'];
                   $start=($id-1)*$limit;
               }

              $query=mysql_query("select * from test LIMIT $start, $limit");
             echo "<ul>";
             while($query2=mysql_fetch_array($query))
             {
                     echo "<li>".$query2['name']."</li>";
             }
             echo "</ul>";
             $rows=mysql_num_rows(mysql_query("select * from test"));
             $total=ceil($rows/$limit);

            if($id>1)
            {
              echo "<a href='?id=".($id-1)."' class='button'>PREVIOUS</a>";
            }
            if($id!=$total)
             {
                 echo "<a href='?id=".($id+1)."' class='button'>NEXT</a>";
             }

             echo "<ul class='page'>";
             for($i=1;$i<=$total;$i++)
             {
                if($i==$id) { echo "<li class='current'>".$i."</li>"; }

                else { echo "<li><a href='?id=".$i."'>".$i."</a></li>"; }
             }
             echo "</ul>";
     ?>
           </div>
   </body>
   </html>

0 个答案:

没有答案