1

I want to design pagination for desktop and mobile devices with the condition that on desktop view i want to display the 3 rows max And in mobile view i want to display the 1 row max per page i have the following pagination script which is working for static condition but i want it dynamic for desktop and mobile. Please help me and thanks in advance.

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>
Darshan Jadiye
  • 231
  • 3
  • 14
  • Given that your server won't reliably know what device, or more importantly what screen size, a user has you're probably not going to be able to solve this through pure PHP alone. – Tom Apr 06 '17 at 11:46
  • Also **please please please** [review this link about what you shouldn't be using `mysql_` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Tom Apr 06 '17 at 11:48
  • but i think i can detect the request from where its come in PHP – Darshan Jadiye Apr 06 '17 at 11:51
  • if i cant do that with php then please tell me the alternate solution i also have a knowledge about js and jquery thank you – Darshan Jadiye Apr 06 '17 at 11:53
  • I would do it with css using a combination of the `@media` tag to determine screen size and `display: none` to hide the other menu (render them both with php if that's not too expensive). – glaux Apr 06 '17 at 12:08
  • then what if i press next button ? – Darshan Jadiye Apr 06 '17 at 12:11

0 Answers0