Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa PHP how to make paging with class and ajax

Have Programming Question? Ask it here!
 
 
 


dodhiya imran s
how to make paging with class and ajax
1 Answer(s)      3 years and a month ago
Posted in : PHP


paging with class and ajax


Advertisement
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);
?> 


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 elements invisible ?
How to make elements invisible ?   How to make elements invisible
how to make this pattern???
how to make this pattern???  how to make following pattern in javascript
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 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 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 label left alignment?
how to make a label left alignment?  how to make a label left alignment
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 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
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
How to make directory in java
Description: This example demonstrate how to create a directory at specified path. Code: import java.io.File; public ... is that it will make a dir at root directory of C drive
How to make a transparent text
How to make a transparent text Learn how to make a transparent...) and make formatting as looking here. Write Text: Now write your text as you like. I have written here "Text". After writing text make copy (Ctr
JSP Paging issue
JSP Paging issue  Hi; what should I have to write insted of "SQLCALCFOUND_ROWS" for MS-SQL database Amrit
Server side Paging in jsp ?
Server side Paging in jsp ?  Hi i am student of It . i am learning jsp-servlet and i am trying to do paging in my report generation but i want to do server side paging and i am using oracle 10g in back end . it will be very
How to make halo effect
How to make halo effect       Now get ready to learn a simple way to make a halo effect on the picture, follow to make it. Take a picture: Capture any picture to give
How to make a bone, make a bone, a bone
How to make a bone       This example bone design example, It is very easy. If you are looking for, please follow now. New File: Create a new file. Rounded rectangle
how to make multiple choice questions
how to make multiple choice questions  I have to make a multiple choice choice using JSP/Servlets. I created a a session bean for the questions and answers. how to associate group of questions to a user? so each user will have
How to Make iPhone Window Application
How to Make iPhone Window Application  Hi, For Making iphone window application, what parameters i have to follow or provide example related to iphone window application. Thanks
How To Make This Program - Java Beginners
How To Make This Program  How To Make Java Calculation program I... number, prints it, then calculates the sum... output: 59 14 5 please help to make this program  import java.io.*;import java.lang.*;class stringnumber
how to make combinations - Development process
how to make combinations  import java.util.*; interface Expression { public void interpret(ArrayList exp); } class OrExpression implements... to be written here?? } } class AndExpression implements Expression { public void
How to make query and abstraction in Java
How to make query and abstraction in Java  Hi, I read the lessons you have in the sites. They are really useful. However, I could not write codes... PostgreSQL database, and I want to make a query and abstraction for a table. Could
How to make a button of different behaviour?
How to make a button of different behaviour?  Suppose In a jsp page I have a button SAVE with id="btnSave" value="SAVE" and a javascript function... ajaxInsertUpdateData(document.getElementByID("btnSave1").value,......); How to do
how to make employee i card
how to make employee i card  hello friends can anyone help me.. I have to make a project to make Identity card for employees...but i am facing problems with database and jsp connection ... also tell me how to retrive data
JSP Paging Example in Datagrid - JSP-Servlet
JSP Paging Example in Datagrid  Hi, I have tested JSP Paging Example... for "propertyDesc" in object of class "com.flank.ers.SimpleAdverTisment" using... how can i solve the above error. Quick response is highly appreciated. Salam
Ajax
Ajax  How to learn AJAX
How to make a design document for exception handling in java
How to make a design document for exception handling in java  How to make a design document for exception handling
Paging or pagination - Development process
Paging or pagination  1.how to do paging or pagination in jsp using servlets? I have a 20 records ,i have to show them in 2 pages like pages 1 2... i done this but i m geting starting 10 records correctly but i m unable
How to make frame in java
How to make frame in java We are going to discus about frame in java. In this example We have make frame in java Swing. We have created JFrame class...; public class FrameExample extends JFrame{ private static final long
how can i make monthly register ?
how can i make monthly register ?  how can i make monthly register ? iam using jdeveloper
how to set class path
how to set class path  how to set class path in java
Advertisements
 

 

 

DMCA.com