how to make paging with function ?

Ads

 
 
 

Share on Google+Share on Google+

dodhiya imran s
how to make paging with function ?
1 Answer(s)      5 years and 11 months ago
Posted in : PHP

how to make paging with function ?

Ads
View Answers

June 6, 2011 at 11:04 AM


//this page is display.php

<?php

$con=mysql_connect("localhost","root","");
if(!$con)
{
die("you can connect please check". mysql_error());
}
mysql_select_db(mydata,$con);
include "pagingcheck.php";
$rowsPerPage = 2;
$pageNum = 1;
$offset = ($pageNum - 1) * $rowsPerPage;

$query = mysql_query("SELECT * FROM login LIMIT $offset, $rowsPerPage");

echo "<table border='1'>
<tr>
<th>id</th>
<th>first name</th>
<th>last name</th>
<th>user</th>
<th>password</th>
<th>gender</th>
<th>e-mailid</th>
<th>mobile no</th>
<th>image</th>
<th>edit</th>
<th>delete</th>
</tr>";


while($row = mysql_fetch_array($query))
  {
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['fname'] . "</td>";
  echo "<td>" . $row['lname'] . "</td>";
  echo "<td>" . $row['user'] . "</td>";
  echo "<td>" . $row['pass'] . "</td>";
  echo "<td>" . $row['gender'] . "</td>";
  echo "<td>" . $row['mail'] . "</td>";
  echo "<td>" . $row['mno'] . "</td>";
  echo "<td>" . "<img src='".$row['file']."' height='25px' width='25'/>" . "</td>";
  //echo "<td>" . "<a href='edit.php'> edit </a>". "</td>";
    ?>
  <td><a href="edit.php?id=<? echo $row['id']; ?>">edit</a></td>  
 <td><a href="javascript:confirmation(<? echo $row['id']; ?>)">delete</a> </td> 

  <?php

  echo "</tr>";
  }
echo "</table>";


$query = mysql_query("SELECT COUNT(id) AS numrows FROM login ");
//this page in only function call and next page in function body
paging($offset,$rowsPerPage,$query);

?>

//this page is pagingcheck.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>
<?php


function paging($offset,$rowsPerPage,$query)
{
    if(isset($_GET['page']))
    {
        $pageNum = $_GET['page'];
    }
    $row = mysql_fetch_array($query);
    $numrows = $row['numrows'];
    $maxPage = ceil($numrows/$rowsPerPage);

        $self = $_SERVER['PHP_SELF'];
        $nav = '';
        for($page = 1; $page <= $maxPage; $page++)
        {
            if ($page == $pageNum)
            {
                $nav .= " $page "; // no need to create a link to current page

            }
            else
            {
                $nav .= " <a href=\"$self?page=$page\">$page</a> ";
            }
        }
        if ($pageNum > 1)
        {
            $page = $pageNum - 1;
            $prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
            $first = " <a href=\"$self?page=1\">[First Page]</a> ";
        }
        else
        {
            $prev = ' '; // we're on page one, don't print previous link
            $first = ' '; // nor the first page link
        }
        if ($pageNum < $maxPage)
        {
            $page = $pageNum + 1;
            $next = " <a href=\"$self?page=$page\">[Next]</a> ";
            $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
        }
        else
        {
            $next = ' '; // we're on the last page, don't print next link
            $last = ' '; // nor the last page link
        }

echo $nav . "<br />";
echo $prev . "  " . $next . "<br />";
echo $first . "  " . $last;

}
?>

Ads









Related Tutorials/Questions & Answers:
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