how to make paging with class and ajax

Ads

 
 
 

Share on Google+Share on Google+

dodhiya imran s
how to make paging with class and ajax
1 Answer(s)      5 years and 10 months ago
Posted in : PHP

paging with class and ajax

Ads
View Answers

July 21, 2011 at 6:44 PM


imran.php

<?php 
class pagination{
            var $row;
            var $p=1; 
            var $limits;
            var $count_all=0,$sql,$total,$table,$totalres,$totalpages;
            var $r,$i;

            function connect(){

                $connectect = mysql_connect("localhost","root","") or die(mysql_error());
                $selected = mysql_select_db(mydata) or die(mysql_error());


            }

            function setMax($max_r){

                  $this->p = $_GET['p'];
                  $this->max_r = $max_r;

                      if(empty($this->p))
                      {
                        $this->p = 1;
                      }

                  $this->limits = ($this->p - 1) * $this->max_r;

            }    

            function setData($table){

                  $this->table = $table;
                  $this->sql = "SELECT * FROM ".$this->table." LIMIT ".$this->limits.",".$this->max_r."";
                    $this->sql = mysql_query($this->sql) or die(mysql_error());
                  $this->total = "SELECT * FROM ".$this->table."";
                  $this->totalres =  mysql_query($this->total) or die(mysql_error());
                  $this->count_all = mysql_num_rows($this->totalres);
                  $this->totalpages = ceil($this->count_all / $this->max_r);
            }

            function display(){

                    $fields=mysql_num_fields($this->totalres);


                      echo "<table border=1 width=100%><tr>";
                        for ($i=0; $i < mysql_num_fields($this->sql); $i++) //Table Header
                        { 
                            print "<th>".mysql_field_name($this->sql, $i)."</th>"; 
                        }
                        echo "</tr>";
                        while ($row = mysql_fetch_row($this->sql)) 
                        { 
                            echo "<tr>";
                            for ($f=0; $f < $fields; $f++) 
                            {
                                echo "<td>$row[$f]</td>"; 
                            }
                            echo "</tr>\n";
                        }
                        echo "</table><p>";

            }

            function displayLinks($show){

                  $this->show = $show; // How many links to show

                   echo "<br><br>";

                  if($this->p > 1) // If p > then one then give link to first page
                  {
                        echo "<a href=?p=1> [FIRST] </a>  ";    
                  }
                  else{ // else show nothing
                        echo "";
                  }
                  if($this->p != 1){ // if p aint equal to 1 then show previous text

                          $previous = $this->p-1;
                          echo "<a href=?p=$previous> [ PREVIOUS ] </a>";

                  }
                  else{ //else show nothing
                          echo "";
                  } 
                  for($i =1; $i <= $this->show; $i++) // show ($show) links
                  {

                        if($this->p > $this->totalpages){ // if p is greater then totalpages then display nothing
                            echo "";
                        }
                        else if($_GET["p"] == $this->p){ //if p is equal to the current loop value then dont display that value as link
                            echo $this->p;
                        }
                        else{
                            echo " <a href=?p=".$this->p."&maxrow=".$this->max_r."> ( ".$this->p.") </a>"; // else display the rest as links
                        }

                        $this->p++; //increment $p  
                  }
                    echo "....."; // display dots

                   if($_GET["p"] == $this->totalpages){// if page is equal to totalpages then  dont display the last page at the end of links
                            echo "";
                   }
                   else // else display the last page link after other ones
                   {
                        echo "<a href=?p=".$this->totalpages."&maxrow=".$this->max_r."> ( ".$this->totalpages.") </a>"; 
                   }
                   if($_GET["p"] < $this->totalpages)// if p is less then total pages then show next link
                   {
                        $next = $_GET["p"] + 1;
                        echo "<a href=?p=$next&maxrow=".$this->max_r."> [ NEXT >] </a>";    
                   }

                   echo "<br><br>";

            }

    }
?>
<html>
    <head>
    <title> paging with class and ajax</title>
        <script type="text/javascript">
            function showUser(str)
            { 
            if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
            }
            else
            {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange=function()
            {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            document.getElementById("paging").innerHTML=xmlhttp.responseText;
            }
            }
            xmlhttp.open("GET","paging.php?maxrow="+str,true);
            xmlhttp.send(); }
        </script>
    </head>
    <body>
        <form name="frm" method="post" >
            select row per page
            <select name="users" onChange="showUser(this.value)">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            </select>
        </form>
        <br />
        <div id="paging">
            <?php 
            $page= new pagination;
            $page->connect();

            if(isset($_REQUEST['maxrow'])){
            $page->setMax($_REQUEST['maxrow']);
            }else{
            $page->setMax(2);
            }
            $page->setData("login");
            $page->display();
            $page->displayLinks(5);
            ?>
        </div>
    </body>
</html> 


paging.php

<?php
$row=$_GET['maxrow'];
class pagination{

            var $row;
            var $p=1; 
            var $limits;
            var $count_all=0,$sql,$total,$table,$totalres,$totalpages;
            var $r,$i;

            function connect(){

                $connectect = mysql_connect("localhost","root","") or die(mysql_error());
                $selected = mysql_select_db(mydata) or die(mysql_error());


            }

            function setMax($max_r){

                  $this->p = $_GET['p'];
                  $this->max_r = $max_r;

                      if(empty($this->p))
                      {
                        $this->p = 1;
                      }

                  $this->limits = ($this->p - 1) * $this->max_r;

            }    

            function setData($table){

                  $this->table = $table;
                  $this->sql = "SELECT * FROM ".$this->table." LIMIT ".$this->limits.",".$this->max_r."";
                    $this->sql = mysql_query($this->sql) or die(mysql_error());
                  $this->total = "SELECT * FROM ".$this->table."";
                  $this->totalres =  mysql_query($this->total) or die(mysql_error());
                  $this->count_all = mysql_num_rows($this->totalres);
                  $this->totalpages = ceil($this->count_all / $this->max_r);
            }

            function display(){

                    $fields=mysql_num_fields($this->totalres);


                      echo "<table border=1 width=100%><tr>";
                        for ($i=0; $i < mysql_num_fields($this->sql); $i++) //Table Header
                        { 
                            print "<th>".mysql_field_name($this->sql, $i)."</th>"; 
                        }
                        echo "</tr>";
                        while ($row = mysql_fetch_row($this->sql)) 
                        { 
                            echo "<tr>";
                            for ($f=0; $f < $fields; $f++) 
                            {
                                echo "<td>$row[$f]</td>"; 
                            }
                            echo "</tr>\n";
                        }
                        echo "</table><p>";

            }

            function displayLinks($show){

                  $this->show = $show; // How many links to show

                   echo "<br><br>";

                  if($this->p > 1) // If p > then one then give link to first page
                  {
                        echo "<a href=?p=1&maxrow=".$this->max_r."> [FIRST] </a>  ";    
                  }
                  else{ // else show nothing
                        echo "";
                  }
                  if($this->p != 1){ // if p aint equal to 1 then show previous text

                          $previous = $this->p-1;
                          echo "<a href=?p=$previous&maxrow=".$this->max_r."> [ PREVIOUS ] </a>";

                  }
                  else{ //else show nothing
                          echo "";
                  } 
                  for($i =1; $i <= $this->show; $i++) // show ($show) links
                  {

                        if($this->p > $this->totalpages){ // if p is greater then totalpages then display nothing
                            echo "";
                        }
                        else if($_GET["p"] == $this->p){ //if p is equal to the current loop value then dont display that value as link
                            echo $this->p."&maxrow=".$this->max_r;
                        }
                        else{
                            echo " <a href=?p=".$this->p."&maxrow=".$this->max_r."> ( ".$this->p.") </a>"; // else display the rest as links
                        }

                        $this->p++; //increment $p  
                  }
                    echo "....."; // display dots

                   if($_GET["p"] == $this->totalpages){// if page is equal to totalpages then  dont display the last page at the end of links
                            echo "";
                   }
                   else // else display the last page link after other ones
                   {
                        echo "<a href=?p=".$this->totalpages."&maxrow=".$this->max_r."> ( ".$this->totalpages.") </a>"; 
                   }
                   if($_GET["p"] < $this->totalpages)// if p is less then total pages then show next link
                   {
                        $next = $_GET["p"] + 1;
                        echo "<a href=?p=$next&maxrow=".$this->max_r."> [ NEXT >] </a>";    
                   }

                   echo "<br><br>";

            }

    }
$page= new pagination;
$page->connect();
$page->setMax($row);
$page->setData("login");
$page->display();
$page->displayLinks(5);
?> 

Ads









Related Tutorials/Questions & Answers:
how to make paging with class and ajax
how to make paging with class and ajax  paging with class and ajax
how to make paging with class and ajax
how to make paging with class and ajax  paging with class and ajax   imran.php <?php class pagination{ var $row...; paging with class and ajax function showUser
Advertisements
how to make paging with function ?
how to make paging with function ?  how to make paging with function... "); //this page in only function call and next page in function body paging($offset... Document <?php</p> function paging($offset,$rowsPerPage,$query
paging - Ajax
paging  i want sample code for paging using pager taglibs
how make ID - Ajax
how make ID  how make a ID in eyeball chat
datagid with paging using jsp - Ajax
datagid with paging using jsp  datagrid with paging using ajax and jsp  Hi friend, For read more information : http://www.roseindia.net/jsp/data-grid.shtml Thanks
Paging
Paging  How does paging in struts by use oracle database? Thanks in advance
Chat and make conference - Ajax
Chat and make conference  i am doing online messenger System in j2ee and AJAX. plz help me how i can see the online friends and off line friends in chat windows. if i select one friend which is online then how a new window
How to make a ajax application which take data from textarea and that page is not refreshing.
How to make a ajax application which take data from textarea and that page is not refreshing.  I am doing a application in that i am using Spring... done this without using AJAX but I want to do this using AJAX
AJAX Queue Class
AJAX Queue Class       This is a JavaScript class that makes using AJAX really, REALLY simple and robust. It supports every browser capable of AJAX (including IE5/Win98) and manages
how to make this pattern???
how to make this pattern???  how to make following pattern in javascript
How to make elements invisible ?
How to make elements invisible ?   How to make elements invisible
How to use Servlet and Ajax?
How to use Servlet and Ajax?  How to use Servlet and Ajax
how to make exampage in jsp ?
how to make exampage in jsp ?  how to make a online exam page in jsp and servelet
How to make a file in java
Description: This example demonstrate how to make a file and write string in it. To create a file in java we use the File Class. The instance of the File class is immutable that means the pathname represented by the File object
how to make a program on array
how to make a program on array  When you make a program on array that the element will move downward and upward and when you input twice 0 then thats the time that it will not move. pls. give me a formula...tnx
How to make selectOneMenu scrollable
How to make selectOneMenu scrollable  how to make the selectOneMenu scrollable? I have around 20 values in drop down and i want the scrollable functionality after 5 values. Kindly reply as soon as possible. Thanks Shikha
how make excel
how make excel  how make excel spreadsheet IN JAVA. please send this code argently   Hello Friend, Try the following code: import... org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFCell; public class
how to make multiple rectangles
how to make multiple rectangles  I,m a beginner , m sorry... javax.swing.JFrame; public class Output extends JFrame { /** * */ public...(JFrame.EXIT_ON_CLOSE); //Set JFrame size setSize(400,400); //Make JFrame
how to ajax components are synchronized
how to ajax components are synchronized  How to ajax components are synchronized   Hi, Ajax consist of set of technologies to get the data... is responsible to getting the server data. Please read Ajax First Example. Thanks
JSP Paging issue
JSP Paging issue  Hi; How to display large number of users- account profile with photo can be placed in continuous pages using JSP code . If any one have solution please help me . Amrit;   Visit Here
how to fetch the record using AJAX? - Ajax
how to fetch the record using AJAX?  Can anyone tell me how to fetch the records from database using Ajax
How to work with Ajax in spring
How to work with Ajax in spring  give some sample code for ajax with spring (example like if i select a state from one drop down in another drop down related districts should come
Paging in jsp - Java Beginners
Paging in jsp  Hi all, I want to make paging in jsp please send the code and process also. Like 1,2,3,4. its urgent...please send  Hi Friend, Try the following code: pagination.jsp
How to use ajax in jsp?
How to use ajax in jsp?  Hi, How i can access the server-side data in JSP using the Ajax? Thanks   Hi, You can use the Ajax code to access the server side data from JSP page. Check the tutorial Combo Box Using Ajax
How to send data by ajax to servlet? - Ajax
How to send data by ajax to servlet?  Hi, Can i send a value from a HTML file to servlet via Ajax? If it is possible please give me a sample code Thanks
how to make a label left alignment?
how to make a label left alignment?  how to make a label left alignment
how to make a field left justification
how to make a field left justification  how to make a field left justification.need code.thanks in advance
How to make a chain, make a chain, chain
How to make a chain       To learn how to design a chain in the photoshop has become so easy by this example, it has some important instruction to make it so follow
Paging in JSP - JSP-Servlet
Paging in JSP  Sir, The error shows in SELECT Query while executing the following query in Paging "SELECT * FROM tablename LIMIT 0,10" What is the exact query in MsAccess for Using Limit.Thsmk you for ur replies
How to make bubbles, make bubbles, bubbles
How to make bubbles      ... to make it easily to draw. New File: First take colored background file. Draw... Overlay, use same both settings as given below. Duplicate: Now make
Tutorials   
Java Spring Hibernate Struts Training I am Java programmer. Should I learn Java Script or Python? Delete multiple records with pagination by selecting checkboxes How to add one hour in php date? connection in php connection in php connection in php PHP magento how to make previous and next Button Display Data in php session written exam display database results question create a simple form Magento Strings in PHP Zend Framework Installation in xampp? How to prevent adding duplicate items to the shopping cart php problem maximum execution time of 30 seconds exceeded in php Call-time pass-by-reference has been removed in HTTP_POST_VARS is deprecated $_GET[] index is not defined Function mysql_db_query() is deprecated Function mysql_db_query() is deprecated Function split() is deprecated Fatal error: Call to undefined function session_register() in .php file php tag not working Error reporting in PHP Why are MySQL Routines and Views not used with PHP? How to add Click to copy function to my wordpres blog? connection of php to MySQL. loan calculator Datepicker not getting called through include function of php change url string integrate login in php Installation of wamp server Display PHP clock with user input date and time value in div from php, reloading form pre-populate form developing a system using php n mysql Configure apache Tomcat to work with Eclipse and PDT in php How to display a file for 24 hours? LOGIN ERROR LOGIN FAILED", $_SESSION['login fail']='0',}?> I GOT ERROR FOR MY PROJECT PHP Sending emails and insert into trable Tutorial college Student Admission System PLZ HELP ME. i need php code.

Ads

 
Advertisement null

Ads