I want Pagination in php

<?php
require_once('upper.php');

// Connects to your Database
require_once('database.php');
//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($pagenum)))
{
$pagenum = 1;
}

//Here we count the number of results
//Edit $data to be your query

$query = "SELECT * FROM events";
$result = mysqli_query($dbc,$query) or die('Not');
$rows = mysqli_num_rows($result);

//This is the number of results displayed per page
$page_rows = 2;

//This tells us the page number of our last page
$last = ceil($rows/$page_rows);

//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}

//This sets range that we will display in our query
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;

//This is your query again, the same one... the only difference is we add $max into it
$result = mysqli_query($dbc,"SELECT * FROM events $max") or die('Not');

//This is where you display your query results
while($row = mysqli_fetch_array( $result))
{
$Title=$row['Title'];
$City=$row['City'];
$Content=$row['Content'];
//$Photo=$row['Photo'];
$Date=$row['Date'];
$EventId=$row['EventId'];
$Photo=$row['Photo'];
//echo $Photo;

echo    "<div><table border='0' cellspacing='0' cellpadding='0' width='389'>
            <tr>
                <td><img src='images/events_2.png' width='389' height='10'></td>
            </tr>
            
            <tr>
                <td background='images/events_2_bg.png'>
                    <table border='0' cellspacing='0' width='359'>
                        <tr>
                                    
                            <td>
                                <tr>
                                    <table width='100%' border='0' cellspacing='0' >
                                        <tr>
                                            <td rowspan='3'><img src='$Photo' width='80' height='60'></td>            
                                            <td align='left' valign='top' width='180'>$City</td>
                                            <td align='left' valign='top'>$Date</td>                                            
                                        </tr>
                                        <tr>                                            
                                            <td colspan='3' align='left' valign='top'>$Title</td>                        
                                            
                                        </tr>
                                        <tr>
                                            <td colspan='2'><a href='KnowMore.php?EventId=".$row['EventId']."'>Know more </a> / <a href='EventParticipator.php?EventId=".$row['EventId']."'>click here to participate</a></td>
                                        </tr>
                                        
                                    </table>
                                </tr>
                            
                        </tr>    
                    </table>                    
                </td>
            </tr>
            
            <tr>
                <td><img src='images/events_2_bottom.png' width='389' height='10' ></td>
            </tr>
            
        </table></div>";

}


echo "<p>";

// This shows the user what page they are on, and the total number of pages
echo " --Page $pagenum of $last-- <p>";

// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['pagination.php']}?pagenum=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['page_test.php']}?pagenum=$previous'> <-Previous</a> ";
}
echo $PHP_SELF;


//just a spacer
echo " ---- ";

//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['page_test.php']}?pagenum=$next'>Next -></a> ";
echo " ";
echo " <a href='{$_SERVER['page_test.php']}?pagenum=$last'>Last ->></a> ";
}
require_once('lower.php');
?>

Hi friends…
I want to paginate my page but it not works properly.
It displays first 2 rows but on clicking “Next” nothing happens.
It displays error also “Notice: Undefined variable: PHP_SELF in C:\wamp\www\NGOProject\Elite Brigade\pagination.php on line 112” and “Notice: Undefined index: page_test.php in C:\wamp\www\NGOProject\Elite Brigade\pagination.php on line 124”…
I don’t know what to do???
Plz help me anyone???

I think this site will help you to prepare pagination:::
http://www.99points.info/2010/05/ajax-pagination-create-ajax-pagination-using-php-jquery-and-ajax/

Look here.
http://www.phpclasses.org/search.html?words=pagination&go_search=1

this demo might help. I’ve included the sql to create the table the demo uses.

index.php

 
<?php 
session_start(); 
//---------------------------------------------------------------------------------------------------------------------- 
//connect to the database 
$DBUserName = ""; //database user account name 
$DBPassword = ""; //database user account password 
$DBName = ""; //name of database 
 
@$conn = mysql_connect("localhost",$DBUserName,$DBPassword) or die('<br />1-Cannot connect to the database at the moment.<br /><br />Please try again later.<br />'); //connect to mysql 
@$isDbSelected = mysql_select_db($DBName, $conn) or die('<br />1-Cannot connect to the database at the moment.<br /><br />Please try again later.<br />'); //connect to the db 
//---------------------------------------------------------------------------------------------------------------------- 
include('paginator.php'); 
if(!isset($_SESSION['pageMaker'])) { 
$linesPerPage = 3; //number of lines to print per page 
$numLinksDisplay = 5; //number of page links to display at a time 
$dbTable = 'tblperson'; //database table to page results 
$tableCols = array('*'); //array of column names of records to be retrieved 
$pageMaker = new paginator($linesPerPage,$numLinksDisplay,$dbTable,$tableCols,$conn); 
} else { 
$pageMaker = unserialize($_SESSION['pageMaker']); 
} 
//set current page 
if(isset($_GET['type'])) $pageMaker->setCurrPage($_GET['type'],$_GET['txtPgNum']); 
//------------------------------------------------------------ 
//Code to retrieve the rows to display on the current page 
//------------------------------------------------------------ 
if(!$rs = $pageMaker->getPageRecords($conn)) die('<p>**ERROR - cannot get records for the page at the moment.</p>'); 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
<title>Pagination</title> 
<!-- add the stylesheet for the page links --> 
<?php echo $pageMaker->getLinkStyles(); ?> 
</head> 
<body> 
<!-- Display the page links --> 
<div id="page_links_wrapper"> 
<?php $pageMaker->showLinks(); ?> 
</div> 
<!-- Code block to display the DB records for this page--> 
<table> 
<?php 
while($row=mysql_fetch_assoc($rs)) { 
echo '<tr><td>'.$row['fldPersonID'].'</td><td>'.$row['fldGivenName'].'</td><td>'.$row['fldFamilyName'].'</td></tr>'; 
} 
mysql_free_result($rs); 
mysql_close($conn); 
?> 
</table> 
<!-- End of code block to display the DB records for this page--> 
<?php 
//hide or display the 'previous' and 'next' buttons as required 
$pageMaker->applyLinkStyles(); 
//serialise the session's pageMaker object for the next call to this page 
$_SESSION['pageMaker'] = serialize($pageMaker); 
?> 
</body> 
</html> 
 

paginator.php

 
<?php
class paginator {
// Properties
protected $linesPerPage; //number of lines to print per page
protected $numLinksDisplay; //number of page links to display at a time
protected $colNames = array(); //array of column names
protected $table; //database table to get records from 
protected $currPage;
protected $totRows;
protected $totPages;
protected $offset;
/* * *********************************************************************
Class Constructor
* ********************************************************************* */
public function __construct($numLines, $numLinks, $dbTable, $tableCols, $conn) {
$this->linesPerPage = ceil($numLines);
$this->numLinksDisplay = ceil($numLinks);
$this->table = $dbTable;
$this->colNames = (in_array('*', $tableCols)) ? array('*') : $tableCols;
$this->currPage = 1;
$this->offset = 0;
$this->initialise($conn);
}
/* * *********************************************************************
Class Accessor Methods
* ********************************************************************* */
public function setCurrPage($type, $pageNum) {
$pageNum = ceil($pageNum);
//check which link was clicked
switch ($type) {
case 'pageLink':
$this->currPage = $pageNum;
break;
case 'prevNext':
$this->currPage = $this->currPage + $pageNum;
if ($this->currPage < 1)
$this->currPage = 1;
if ($this->currPage > $this->totPages)
$this->currPage = $this->totPages;
break;
case 'firstPg':
$this->currPage = 1;
break;
case 'lastPg':
$this->currPage = $this->totPages;
break;
}
//calculate the offset of the first record number to retrieve from the DB for this page
$this->offset = ($this->currPage * $this->linesPerPage) - $this->linesPerPage;
if ($this->offset < 0)
$this->offset = 0;
if ($this->offset > $this->totRows)
$this->offset = $this->totRows;
//echo '<br /><br />type = '.$type,'<br />Page request = '.$pageNum.'<br />Current page = '.$this->currPage.'<br />Offset = '.$this->offset.'<br /><br />'; 
}
//-----------------------------------------------
public function getCurrPage() {
return $this->currPage;
}
/* * *********************************************************************
Class Methods
* ********************************************************************* */
private function initialise($conn) {
//count all the records to work out max number of rows and number of pages needed 
$query = 'select count(*) "numRows" from ' . $this->table;
$rs = @mysql_query($query, $conn) or die("<p>3-Server is busy.<br />Please try again later.</p>");
$row = mysql_fetch_assoc($rs);
$this->totRows = $row['numRows']; //total number of rows to display
@mysql_free_result($rs);
if ($this->totRows % $this->linesPerPage == 0) {
$this->totPages = $this->totRows / $this->linesPerPage;
} else {
$this->totPages = round(($this->totRows / $this->linesPerPage) + 0.5); //total number of pages required
}
$this->numLinksDisplay = ($this->numLinksDisplay > $this->totPages) ? $this->totPages : $this->numLinksDisplay;
//echo $this->totRows.'<br />'.$this->totPages.'<br />'.$this->numLinksDisplay; 
}
//-------------------------------------------------------------------------------------
public function getPageRecords($conn) {
//build string of column names for the query
$str = '';
foreach ($this->colNames as $val) {
$str .= $val . ',';
}
$str = substr_replace($str, '', strlen($str) - 1); //remove the last comma
$query = 'select ' . $str . ' from ' . $this->table . ' limit ' . $this->offset . ',' . $this->linesPerPage;
//echo '<br />query = '.$query,'<br />';
return @mysql_query($query, $conn);
}
//-------------------------------------------------------------------------------------
public function showLinks() {
if ($this->totPages <= 1)
return; //no need to display any links
echo '<div id="page_links_summ">' .
'<p id="totPages">Total pages: ' . $this->totPages . '</p>' .
'<p id="totRows">Total records: ' . $this->totRows . '</p>' .
'</div>' .
'<div id="page-links-container">' .
'<ul id="page-links">' .
'<li id="liFirstPage"><a href="' . $_SERVER['PHP_SELF'] . '?txtPgNum=-1&amp;type=firstPg" title="Click to view first page">First</a></li>' .
'<li id="liPrevPage"><a href="' . $_SERVER['PHP_SELF'] . '?txtPgNum=-1&amp;type=prevNext" title="Click to view previous page">Previous</a></li>';
//calculate the min and max link numbers to display for this page
if ($this->numLinksDisplay % 2 == 0) { //even number of links to display
$limit1 = $this->currPage - $this->numLinksDisplay / 2;
$limit2 = $this->currPage + ($this->numLinksDisplay / 2) - 1;
} else { //odd number of links to display
$limit1 = $this->currPage - ($this->numLinksDisplay - 1) / 2;
$limit2 = $this->currPage + ($this->numLinksDisplay - 1) / 2;
}
if ($limit1 < 1 && $this->currPage < $this->numLinksDisplay)
$limit1 = 1;
if ($limit2 > $this->totPages)
$limit2 = $this->totPages;
//adjust the link numbers for when we are within $_SESSION['numLinksDisplay']/2 of either end
if ($this->currPage <= $this->numLinksDisplay / 2)
$limit2 = $this->numLinksDisplay;
if ($this->currPage > $this->totPages - $this->numLinksDisplay / 2)
$limit1 = $this->totPages - $this->numLinksDisplay + 1;
//echo '<br />'.$_SESSION['currPage'].'<br />'.$limit1.'<br />'.$limit2.'<br /><br />';
//display the page links
for ($i = $limit1; $i <= $limit2; $i = $i + 1) {
echo '<li id="liPg' . $i . '"><a href="' . $_SERVER['PHP_SELF'] . '?txtPgNum=' . $i . '&amp;type=pageLink" title="Go to page ' . $i . '">' . $i . '</a></li>';
}
echo '<li id="liNextPage"><a href="' . $_SERVER['PHP_SELF'] . '?txtPgNum=1&amp;type=prevNext" title="Click to view next page">Next</a></li>' .
'<li id="liLastPage"><a href="' . $_SERVER['PHP_SELF'] . '?txtPgNum=-1&amp;type=lastPg" title="Click to view last page">Last</a></li>' .
'</ul>' .
'</div>';
}
//-------------------------------------------------------------------------------------
public function getLinkStyles() {
if ($this->totPages <= 1)
return; //no need to display any links
$str = '<style type="text/css"> ' .
'#page-links-container { ' .
'font-size: 10pt; ' .
'font-family: tahoma, arial, sans serif; ' .
'margin: 0px 0px 0px 0px; ' .
'padding: 0px 0px 0px 0px} ' .
'#page-links-container ul { ' .
'clear: both; ' .
'padding: 0px 0px 0px 0px; ' .
'margin: 0px 0px 20px 0px;' .
'list-style-type: none} ' .
'#page-links-container ul li { ' .
'display: inline; ' .
'color: rgb(0,0,205); ' .
'padding: 3px 4px 3px 4px; ' .
'margin: 0px 0px 0px 6px} ' .
'#page-links-container ul li a { ' .
'text-decoration: none; ' .
'font-size: 10pt} ' .
'#page-links-container ul li a:hover { ' .
'text-decoration: underline} ' .
'#page-links-container ul li a:visited { ' .
'color: rgb(0,0,205);} ' .
'#page_links_summ { ' .
'font-size: 10pt; ' .
'font-family: tahoma, arial, sans serif; ' .
'width: 250px} ' .
'#totPages { ' .
'float: left} ' .
'#totRows { ' .
'float: right} ' .
'</style> ';
return $str;
}
//--------------------------------------------------------------------------------------
public function applyLinkStyles() {
if ($this->totPages <= 1)
return; //no need to display any links
//hide or display the 'previous' and 'next' buttons as required
if ($this->totPages == 1)
echo '<script type="text/javascript">document.getElementById("page-links-container").style.display="none";</script>';
if ($this->currPage == 1) {
echo '<script type="text/javascript">document.getElementById("liPrevPage").disabled = true;</script>';
} else {
echo '<script type="text/javascript">document.getElementById("liPrevPage").disabled = false;</script>';
}
if ($this->currPage == $this->totPages) {
echo '<script type="text/javascript">document.getElementById("liNextPage").disabled = true;</script>';
} else {
echo '<script type="text/javascript">document.getElementById("liNextPage").disabled = false;</script>';
}
//highlight the current page's page link
echo '<script type="text/javascript">document.getElementById("liPg' . $this->currPage . '").style.backgroundColor="rgb(200,200,200)";</script>';
echo '<script type="text/javascript">document.getElementById("liPg' . $this->currPage . '").style.border="1px solid rgb(0,0,0)";</script>';
}
//--------------------------------------------------------------------------------------
}
//end of class
?>

sql script to create the db table

 
CREATE TABLE `tblperson` (
`fldPersonID` int(11) NOT NULL AUTO_INCREMENT,
`fldFamilyName` varchar(20) DEFAULT NULL,
`fldGivenName` varchar(20) DEFAULT NULL,
PRIMARY KEY (`fldPersonID`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
/*Data for the table `tblperson` */
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Sui','Steven');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Student','Mary');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Student','Sam');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Malik','Moore');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Soo','Malinda');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('flinstone','fred');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('rubble','barney');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('flinstone','wilma');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('flinstone','pebbles');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('smart','maxwell');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Soo','Malinda');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Sui','Steven');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Student','Mary');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Student','Sam');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Malik','Moore');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Soo','Malinda');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('flinstone','fred');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('rubble','barney');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('flinstone','wilma');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('flinstone','pebbles');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('smart','maxwell');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Soo','Malinda');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Sui','Steven');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Student','Mary');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Student','Sam');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Malik','Moore');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Soo','Malinda');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('flinstone','fred');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('rubble','barney');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('flinstone','wilma');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('flinstone','pebbles');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('smart','maxwell');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Soo','Malinda');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Sui','Steven');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Student','Mary');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Student','Sam');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Malik','Moore');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Soo','Malinda');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('flinstone','fred');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('rubble','barney');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('flinstone','wilma');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('flinstone','pebbles');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('smart','maxwell');
insert into `tblperson`(`fldFamilyName`,`fldGivenName`) values ('Soo','Malinda');

I have same problem I used Kalon code.
but showing all data from table I want display particular category

where can i put this one

$name = addslashes(strip_tags($_GET[‘category’]));

please any one help me.

thank you in advance

yes, by default the demo will display rows for all the columns in the table.

if you want to specify which columns you want displayed, you need to change this line

$tableCols = arrayCOLOR=#66cc66[/COLOR]; //array of column names of records to be retrieved

[COLOR=#0000cc]in index.php

just enter an array of the columns in your table you want to display.

[/COLOR]
$tableCols = array(‘col_1’,‘col_2’);

[COLOR=#0000cc]So if $name is a column name, you can enter it in $tableCols.

Just make sure $name evaluates to exactly how the column is called in your table.

[/COLOR]

Kalon Thank U for reply here.

this is my category list php


<a href="test7.php?category=Indian Male Models">Indian Male Models</a> 
<a href="test7.php?category=Indian Female Models">Indian Female Models</a>

and this is my test7.php code:


$name = addslashes(strip_tags($_GET['category'])); 
"SELECT * FROM ca_models  WHERE category = '".$name."' and public = 'yes'"

when i select category list that displaying all data from table I want to display only category wise. How can i implement that code in ?

you need to add the where clause in your query to $query in paginator.php

and then add $name to $tableCols in index.php

[COLOR=#0000cc]

 
[COLOR=#0000cc]$tableCols[/COLOR] = [COLOR=#000066]array[/COLOR][COLOR=#66cc66]($name[/COLOR][COLOR=#66cc66])[/COLOR];

And in your case you will also need to rename index.php to test7.php
[/COLOR]

I all ready renamed index.php to test7.php and i used
$tableCols = array($name);
in test7.php

I cannot understanding this one in paginator.php. How can i change
$query = 'SELECT count(*) “numRows” from ’ . $this->table;

this is my query
“SELECT * FROM ca_models WHERE category = '”.$name.“’ and public = ‘yes’”

don’t touch that $query.

change the $query in

function getPageRecordsCOLOR=#66cc66[/COLOR]

to suit your requirements.

this version of my paginator might be a little easier to use.

instead of passing a table name and an array of columns to query to the constructor, you can pass the actual query you want to run instead.

for demo purposes you can use the same sql script as I posted in post #4 to create the test table this demo uses.

whatever you do, don’t mix the 2 versions of index.php and Paginator.php

index.php

 
<?php
session_start();
//---------------------------------------------------------------------------------------------------------------------- 
//connect to the database 
$DBUserName = "root"; //database user account name 
$DBPassword = ""; //database user account password 
$DBName = "test"; //name of database
@$conn = mysql_connect("localhost", $DBUserName, $DBPassword) or die('<br />1-Cannot connect to the database at the moment.<br /><br />Please try again later.<br />'); //connect to mysql
@$isDbSelected = mysql_select_db($DBName, $conn) or die('<br />1-Cannot connect to the database at the moment.<br /><br />Please try again later.<br />'); //connect to the db
//---------------------------------------------------------------------------------------------------------------------- 
include('Paginator.php');
if (!isset($_SESSION['pageMaker'])) {
$linesPerPage = 5; //number of lines to print per page
$numLinksDisplay = 5; //number of page links to display at a time
$query = 'select * from tblperson';
$pageMaker = new Paginator($linesPerPage, $numLinksDisplay, $query, $conn);
} else {
$pageMaker = unserialize($_SESSION['pageMaker']);
}
//set current page 
if (isset($_GET['type']))
$pageMaker->setCurrPage($_GET['type'], $_GET['txtPgNum']);
//------------------------------------------------------------ 
//Code to retrieve the rows to display on the current page 
//------------------------------------------------------------ 
if (!$rs = $pageMaker->getPageRecords($conn))
die('<p>**ERROR - cannot get records for the page at the moment.</p>');
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Pagination</title>
<!-- add the stylesheet for the page links -->
<?php echo $pageMaker->getLinkStyles(); ?> 
</head>
<body>
<!-- Display the page links -->
<div id="page_links_wrapper">
<?php echo $pageMaker->showLinks(); ?>
</div>
<!-- Code block to display the DB records for this page-->
<table>
<?php
while ($row = mysql_fetch_assoc($rs)) {
echo '<tr><td>' . $row['fldPersonID'] . '</td><td>' . $row['fldGivenName'] . '</td><td>' . $row['fldFamilyName'] . '</td></tr>';
}
mysql_free_result($rs);
mysql_close($conn);
?>
</table>
<!-- End of code block to display the DB records for this page-->
<?php
//hide or display the 'previous' and 'next' buttons as required 
$pageMaker->applyLinkStyles();
//serialise the session's pageMaker object for the next call to this page 
$_SESSION['pageMaker'] = serialize($pageMaker);
?>
</body>
</html> 

Paginator.php

 
<?php
class Paginator {
// Properties
protected $linesPerPage; //number of lines to print per page
protected $numLinksDisplay; //number of page links to display at a time
protected $query;
protected $currPage;
protected $totRows;
protected $totPages;
protected $offset;
/* * *********************************************************************
Class Constructor
* ********************************************************************* */
public function __construct($numLines, $numLinks, $query, $conn) {
$this->linesPerPage = ceil($numLines);
$this->numLinksDisplay = ceil($numLinks);
$this->query = $query;
$this->currPage = 1;
$this->offset = 0;
$this->initialise($conn);
}
/* * *********************************************************************
Class Accessor Methods
* ********************************************************************* */
public function setQuery($query, $conn) {
$this->query = $query;
$this->initialise($conn);
}
//-------------------------------------------------------------------------
public function setCurrPage($type, $pageNum) {
$pageNum = ceil($pageNum);
//check which link was clicked
switch ($type) {
case 'pageLink':
$this->currPage = $pageNum;
break;
case 'prevNext':
$this->currPage = $this->currPage + $pageNum;
if ($this->currPage < 1) {
$this->currPage = 1;
}
if ($this->currPage > $this->totPages) {
$this->currPage = $this->totPages;
}
break;
case 'firstPg':
$this->currPage = 1;
break;
case 'lastPg':
$this->currPage = $this->totPages;
break;
}
//calculate the offset of the first record number to retrieve from the DB for this page
$this->offset = ($this->currPage * $this->linesPerPage) - $this->linesPerPage;
if ($this->offset < 0) {
$this->offset = 0;
}
if ($this->offset > $this->totRows) {
$this->offset = $this->totRows;
}
}
//-----------------------------------------------
public function getCurrPage() {
return $this->currPage;
}
/* * *********************************************************************
Class Methods
* ********************************************************************* */
private function initialise($conn) {
//count all the records to work out max number of rows and number of pages needed
$rs = @mysql_query($this->query, $conn) or die("<p>3-Server is busy.<br />Please try again later.</p>");
$this->totRows = mysql_num_rows($rs); //total number of rows to display
@mysql_free_result($rs);
if ($this->totRows % $this->linesPerPage == 0) {
$this->totPages = $this->totRows / $this->linesPerPage;
} else {
$this->totPages = round(($this->totRows / $this->linesPerPage) + 0.5); //total number of pages required
}
$this->numLinksDisplay = ($this->numLinksDisplay > $this->totPages) ? $this->totPages : $this->numLinksDisplay;
//echo $this->totRows.'<br />'.$this->totPages.'<br />'.$this->numLinksDisplay; die();
}
//-------------------------------------------------------------------------------------
public function getPageRecords($conn) {
$query = $this->query . ' limit ' . $this->offset . ',' . $this->linesPerPage;
$rs = @mysql_query($query, $conn);
if (!$rs) {
return false;
} else {
return $rs;
}
}
//-------------------------------------------------------------------------------------
public function showLinks() {
if ($this->totPages <= 1)
return; //no need to display any links
$str = '<div id="page_links_wrap">' .
'<div id="page_links_summ">' .
'<p id="totPages">Total pages: ' . $this->totPages . '</p>' .
'<p id="totRows">Total records: ' . $this->totRows . '</p>' .
'</div>' .
'<div id="page-links-container">' .
'<ul id="page-links">' .
'<li id="liFirstPage"><a href="' . $_SERVER['PHP_SELF'] . '?txtPgNum=-1&amp;type=firstPg" title="Click to view first page">First</a></li>' .
'<li id="liPrevPage"><a href="' . $_SERVER['PHP_SELF'] . '?txtPgNum=-1&amp;type=prevNext" title="Click to view previous page">Previous</a></li>';
//calculate the min and max link numbers to display for this page
if ($this->numLinksDisplay % 2 == 0) { //even number of links to display
$limit1 = $this->currPage - $this->numLinksDisplay / 2;
$limit2 = $this->currPage + ($this->numLinksDisplay / 2) - 1;
} else { //odd number of links to display
$limit1 = $this->currPage - ($this->numLinksDisplay - 1) / 2;
$limit2 = $this->currPage + ($this->numLinksDisplay - 1) / 2;
}
if ($limit1 < 1 && $this->currPage < $this->numLinksDisplay)
$limit1 = 1;
if ($limit2 > $this->totPages)
$limit2 = $this->totPages;
//adjust the link numbers for when we are within $_SESSION['numLinksDisplay']/2 of either end
if ($this->currPage <= $this->numLinksDisplay / 2)
$limit2 = $this->numLinksDisplay;
if ($this->currPage > $this->totPages - $this->numLinksDisplay / 2)
$limit1 = $this->totPages - $this->numLinksDisplay + 1;
//echo '<br />'.$_SESSION['currPage'].'<br />'.$limit1.'<br />'.$limit2.'<br /><br />';
//display the page links
for ($i = $limit1; $i <= $limit2; $i = $i + 1) {
$str = $str . '<li id="liPg' . $i . '"><a href="' . $_SERVER['PHP_SELF'] . '?txtPgNum=' . $i . '&amp;type=pageLink" title="Go to page ' . $i . '">' . $i . '</a></li>';
}
$str = $str . '<li id="liNextPage"><a href="' . $_SERVER['PHP_SELF'] . '?txtPgNum=1&amp;type=prevNext" title="Click to view next page">Next</a></li>' .
'<li id="liLastPage"><a href="' . $_SERVER['PHP_SELF'] . '?txtPgNum=-1&amp;type=lastPg" title="Click to view last page">Last</a></li>' .
'</ul>' .
'</div>' .
'</div>';
return $str;
}
//-------------------------------------------------------------------------------------
public function getLinkStyles() {
if ($this->totPages <= 1) {
return; //no need to display any links
}
$str = '<style type="text/css"> ' .
'#page_links_wrap {' .
//'border: 1px solid green; ' .
'margin: 5px 0px 0px 0px; ' .
'padding: 0px 0px 0px 0px; ' .
'width: 270px}' .
'#page-links-container { ' .
'font-size: 8pt; ' .
'font-family: tahoma, arial, sans serif; ' .
'margin: 0px 0px 0px 0px; ' .
'padding: 0px 0px 0px 0px} ' .
'#page-links-container ul { ' .
'clear: both; ' .
'padding: 0px 0px 0px 0px; ' .
'margin: 0px 0px 10px 0px;' .
'list-style-type: none} ' .
'#page-links-container ul li { ' .
'display: inline; ' .
'color: rgb(0,0,205); ' .
'padding: 3px 4px 3px 4px; ' .
'margin: 0px 0px 0px 6px} ' .
'#page-links-container ul li a { ' .
'text-decoration: none; ' .
'font-size: 8pt} ' .
'#page-links-container ul li a:hover { ' .
'text-decoration: underline} ' .
'#page-links-container ul li a:visited { ' .
'color: rgb(0,0,205);} ' .
'#page_links_summ { ' .
'font-size: 8pt; ' .
'font-family: tahoma, arial, sans serif; ' .
'overflow: hidden} ' .
'#totPages { ' .
//'border: 1px solid blue; ' .
'margin: 5px 0px 5px 10px; padding: 0px 0px 0px 0px;' .
'float: left} ' .
'#totRows { ' .
//'border: 1px solid red; ' .
'margin: 5px 10px 5px 0px; padding: 0px 0px 0px 0px;' .
'float: right} ' .
'</style> ';
return $str;
}
//--------------------------------------------------------------------------------------
public function applyLinkStyles() {
if ($this->totPages <= 1)
return; //no need to display any links
//hide or display the 'previous' and 'next' buttons as required
if ($this->totPages == 1)
echo '<script type="text/javascript">document.getElementById("page-links-container").style.display="none";</script>';
if ($this->currPage == 1) {
echo '<script type="text/javascript">document.getElementById("liPrevPage").disabled = true;</script>';
} else {
echo '<script type="text/javascript">document.getElementById("liPrevPage").disabled = false;</script>';
}
if ($this->currPage == $this->totPages) {
echo '<script type="text/javascript">document.getElementById("liNextPage").disabled = true;</script>';
} else {
echo '<script type="text/javascript">document.getElementById("liNextPage").disabled = false;</script>';
}
//highlight the current page's page link
echo '<script type="text/javascript">document.getElementById("liPg' . $this->currPage . '").style.backgroundColor="rgb(200,200,200)";</script>';
echo '<script type="text/javascript">document.getElementById("liPg' . $this->currPage . '").style.border="1px solid rgb(0,0,0)";</script>';
}
//--------------------------------------------------------------------------------------
}
//end of class
?>

Dear,
Your code works well when i click “next” it displays the 2 page as well but on click 3 page it displays the last page instead of 3 page.
Similarly when i click on “previous” it displays the first page instead of just prevoius page.
Can u tell me solution of it???
Plz…
I m waiting for ur reply…

you haven’t posted your code so I have no way of telling what you have done wrong.

This is participator.php

<?php
//require_once('database.php');
class paginator {
// Properties
protected $linesPerPage; //number of lines to print per page
protected $numLinksDisplay; //number of page links to display at a time
protected $colNames = array(); //array of column names
protected $table; //database table to get records from
protected $currPage;
protected $totRows;
protected $totPages;
protected $offset;
/* * *********************************************************************
Class Constructor
* ********************************************************************* */
public function __construct($numLines, $numLinks, $dbTable, $tableCols, $conn) {
$this->linesPerPage = ceil($numLines);
$this->numLinksDisplay = ceil($numLinks);
$this->table = $dbTable;
$this->colNames = (in_array('*', $tableCols)) ? array('*') : $tableCols;
$this->currPage = 1;
$this->offset = 0;
$this->initialise($conn);
}
/* * *********************************************************************
Class Accessor Methods
* ********************************************************************* */
public function setCurrPage($type, $pageNum) {
$pageNum = ceil($pageNum);
//check which link was clicked
switch ($type) {
case 'pageLink':
$this->currPage = $pageNum;
break;
case 'prevNext':
$this->currPage = $this->currPage + $pageNum;
if ($this->currPage < 1)
$this->currPage = 1;
if ($this->currPage > $this->totPages)
$this->currPage = $this->totPages;
break;
case 'firstPg':
$this->currPage = 1;
break;
case 'lastPg':
$this->currPage = $this->totPages;
break;
}
//calculate the offset of the first record number to retrieve from the DB for this page
$this->offset = ($this->currPage * $this->linesPerPage) - $this->linesPerPage;
if ($this->offset < 0)
$this->offset = 0;
if ($this->offset > $this->totRows)
$this->offset = $this->totRows;
//echo '<br /><br />type = '.$type,'<br />Page request = '.$pageNum.'<br />Current page = '.$this->currPage.'<br />Offset = '.$this->offset.'<br /><br />';
}
//-----------------------------------------------
public function getCurrPage() {
return $this->currPage;
}
/* * *********************************************************************
Class Methods
* ********************************************************************* */
private function initialise($conn) {
//count all the records to work out max number of rows and number of pages needed
$query = 'select count(*) "numRows" from ' . $this->table;
$rs = mysql_query($query,$conn) or die("<p>3-Server is busy.<br />Please try again later.</p>");
$row = mysql_fetch_assoc($rs);
$this->totRows = $row['numRows']; //total number of rows to display
@mysql_free_result($rs);
if ($this->totRows % $this->linesPerPage == 0) {
$this->totPages = $this->totRows / $this->linesPerPage;
} else {
$this->totPages = round(($this->totRows / $this->linesPerPage) + 0.5); //total number of pages required
}
$this->numLinksDisplay = ($this->numLinksDisplay > $this->totPages) ? $this->totPages : $this->numLinksDisplay;
//echo $this->totRows.'<br />'.$this->totPages.'<br />'.$this->numLinksDisplay;
}
//-------------------------------------------------------------------------------------
public function getPageRecords($conn) {
//build string of column names for the query
$str = '';
foreach ($this->colNames as $val) {
$str .= $val . ',';
}
$str = substr_replace($str, '', strlen($str) - 1); //remove the last comma
$query = 'select ' . $str . ' from ' . $this->table . ' limit ' . $this->offset . ',' . $this->linesPerPage;
//echo '<br />query = '.$query,'<br />';
return @mysql_query($query, $conn);
}
//-------------------------------------------------------------------------------------
public function showLinks() {
if ($this->totPages <= 1)
return; //no need to display any links
echo '<div id="page_links_summ">' .
'<p id="totPages">Total pages: ' . $this->totPages . '</p>' .
'<p id="totRows">Total records: ' . $this->totRows . '</p>' .
'</div>' .
'<div id="page-links-container">' .
'<ul id="page-links">' .
'<li id="liFirstPage"><a href="' . $_SERVER['PHP_SELF'] . '?txtPgNum=-1&amp;type=firstPg" title="Click to view first page">First</a></li>' .
'<li id="liPrevPage"><a href="' . $_SERVER['PHP_SELF'] . '?txtPgNum=-1&amp;type=prevNext" title="Click to view previous page">Previous</a></li>';
//calculate the min and max link numbers to display for this page
if ($this->numLinksDisplay % 2 == 0) { //even number of links to display
$limit1 = $this->currPage - $this->numLinksDisplay / 2;
$limit2 = $this->currPage + ($this->numLinksDisplay / 2) - 1;
} else { //odd number of links to display
$limit1 = $this->currPage - ($this->numLinksDisplay - 1) / 2;
$limit2 = $this->currPage + ($this->numLinksDisplay - 1) / 2;
}
if ($limit1 < 1 && $this->currPage < $this->numLinksDisplay)
$limit1 = 1;
if ($limit2 > $this->totPages)
$limit2 = $this->totPages;
//adjust the link numbers for when we are within $_SESSION['numLinksDisplay']/2 of either end
if ($this->currPage <= $this->numLinksDisplay / 2)
$limit2 = $this->numLinksDisplay;
if ($this->currPage > $this->totPages - $this->numLinksDisplay / 2)
$limit1 = $this->totPages - $this->numLinksDisplay + 1;
//echo '<br />'.$_SESSION['currPage'].'<br />'.$limit1.'<br />'.$limit2.'<br /><br />';
//display the page links
for ($i = $limit1; $i <= $limit2; $i = $i + 1) {
echo '<li id="liPg' . $i . '"><a href="' . $_SERVER['PHP_SELF'] . '?txtPgNum=' . $i . '&amp;type=pageLink" title="Go to page ' . $i . '">' . $i . '</a></li>';
}
echo '<li id="liNextPage"><a href="' . $_SERVER['PHP_SELF'] . '?txtPgNum=1&amp;type=prevNext" title="Click to view next page">Next</a></li>' .
'<li id="liLastPage"><a href="' . $_SERVER['PHP_SELF'] . '?txtPgNum=-1&amp;type=lastPg" title="Click to view last page">Last</a></li>' .
'</ul>' .
'</div>';
}
//-------------------------------------------------------------------------------------
public function getLinkStyles() {
if ($this->totPages <= 1)
return; //no need to display any links
$str = '<style type="text/css"> ' .
'#page-links-container { ' .
'font-size: 10pt; ' .
'font-family: tahoma, arial, sans serif; ' .
'margin: 0px 0px 0px 0px; ' .
'padding: 0px 0px 0px 0px} ' .
'#page-links-container ul { ' .
'clear: both; ' .
'padding: 0px 0px 0px 0px; ' .
'margin: 0px 0px 20px 0px;' .
'list-style-type: none} ' .
'#page-links-container ul li { ' .
'display: inline; ' .
'color: rgb(0,0,205); ' .
'padding: 3px 4px 3px 4px; ' .
'margin: 0px 0px 0px 6px} ' .
'#page-links-container ul li a { ' .
'text-decoration: none; ' .
'font-size: 10pt} ' .
'#page-links-container ul li a:hover { ' .
'text-decoration: underline} ' .
'#page-links-container ul li a:visited { ' .
'color: rgb(0,0,205);} ' .
'#page_links_summ { ' .
'font-size: 10pt; ' .
'font-family: tahoma, arial, sans serif; ' .
'width: 250px} ' .
'#totPages { ' .
'float: left} ' .
'#totRows { ' .
'float: right} ' .
'</style> ';
return $str;
}
//--------------------------------------------------------------------------------------
public function applyLinkStyles() {
if ($this->totPages <= 1)
return; //no need to display any links
//hide or display the 'previous' and 'next' buttons as required
if ($this->totPages == 1)
echo '<script type="text/javascript">document.getElementById("page-links-container").style.display="none";</script>';
if ($this->currPage == 1) {
echo '<script type="text/javascript">document.getElementById("liPrevPage").disabled = true;</script>';
} else {
echo '<script type="text/javascript">document.getElementById("liPrevPage").disabled = false;</script>';
}
if ($this->currPage == $this->totPages) {
echo '<script type="text/javascript">document.getElementById("liNextPage").disabled = true;</script>';
} else {
echo '<script type="text/javascript">document.getElementById("liNextPage").disabled = false;</script>';
}
//highlight the current page's page link
echo '<script type="text/javascript">document.getElementById("liPg' . $this->currPage . '").style.backgroundColor="rgb(200,200,200)";</script>';
echo '<script type="text/javascript">document.getElementById("liPg' . $this->currPage . '").style.border="1px solid rgb(0,0,0)";</script>';
}
//--------------------------------------------------------------------------------------
}
//end of class
?>

This is index.php


<?php
require_once('upper.php');
//require_once('database.php');
//$dbc=mysql_connect('localhost','root','','nog') or die('Not Connected');
//session_start();
//----------------------------------------------------------------------------------------------------------------------
//connect to the database
$DBUserName = "root"; //database user account name
$DBPassword = ""; //database user account password
$DBName = "nog"; //name of database
 
$conn = mysql_connect("localhost",$DBUserName,$DBPassword) or die('<br />1-Cannot connect to the database at the moment.<br /><br />Please try again later.<br />'); //connect to mysql
$isDbSelected = mysql_select_db($DBName, $conn) or die('<br />1-Cannot connect to the database at the moment.<br /><br />Please try again later.<br />'); //connect to the db
//----------------------------------------------------------------------------------------------------------------------
include('paginator.php');
//if(!isset($_SESSION['pageMaker'])) {

$linesPerPage = 3; //number of lines to print per page
$numLinksDisplay = 5; //number of page links to display at a time
$dbTable = 'events'; //database table to page results
$tableCols = array('*'); //array of column names of records to be retrieved
$pageMaker = new paginator($linesPerPage,$numLinksDisplay,$dbTable,$tableCols,$conn);
echo 'Ankit';
//} else {
//$pageMaker = unserialize($_SESSION['pageMaker']);
//}

//set current page
if(isset($_GET['type'])) $pageMaker->setCurrPage($_GET['type'],$_GET['txtPgNum']);

//------------------------------------------------------------
//Code to retrieve the rows to display on the current page
//------------------------------------------------------------
if(!$rs = $pageMaker->getPageRecords($conn)) die('<p>**ERROR - cannot get records for the page at the moment.</p>');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Events</title>
<!-- add the stylesheet for the page links -->
<?php echo $pageMaker->getLinkStyles(); ?>
</head>
<body>
<!-- Display the page links -->
<div id="page_links_wrapper">
<?php $pageMaker->showLinks(); ?>
</div>
<!-- Code block to display the DB records for this page-->
<table>
<?php
while($row=mysql_fetch_assoc($rs)) {

$Title=$row['Title'];
$City=$row['City'];
$Content=$row['Content'];
//$Photo=$row['Photo'];
$Date=$row['Date'];
$EventId=$row['EventId'];
$Photo=$row['Photo'];
//echo $Photo;

echo	"<div><table border='0' cellspacing='0' cellpadding='0' width='389'>
			<tr>
				<td><img src='images/events_2.png' width='389' height='10'></td>
			</tr>
			
			<tr>
				<td background='images/events_2_bg.png'>
					<table border='0' cellspacing='0' width='359'>
						<tr>
									
							<td>
								<tr>
									<table width='100%' border='0' cellspacing='0' >
										<tr>
											<td rowspan='3'><img src='$Photo' width='80' height='60'></td>			
											<td align='left' valign='top' width='180'>$City</td>
											<td align='left' valign='top'>$Date</td>											
										</tr>
										<tr>											
										    <td colspan='3' align='left' valign='top'>$Title</td>						
											
										</tr>
										<tr>
											<td colspan='2'><a href='KnowMore.php?EventId=".$row['EventId']."'>Know more </a> / <a href='EventParticipator.php?EventId=".$row['EventId']."'>click here to participate</a></td>
										</tr>
										
									</table>
								</tr>
							
						</tr>	
					</table>					
				</td>
			</tr>
			
			<tr>
				<td><img src='images/events_2_bottom.png' width='389' height='10' ></td>
			</tr>
			
		</table></div>";

//echo '<tr><td>'.$row['fldPersonID'].'</td><td>'.$row['fldGivenName'].'</td><td>'.$row['fldFamilyName'].'</td></tr>';
}
mysql_free_result($rs);
mysql_close($conn);

?>
</table>
<!-- End of code block to display the DB records for this page-->
<?php
//hide or display the 'previous' and 'next' buttons as required
$pageMaker->applyLinkStyles();
//serialise the session's pageMaker object for the next call to this page
$_SESSION['pageMaker'] = serialize($pageMaker);
require_once('lower.php');
?>
</body>
</html>

Help me plzzzzzzzzzzzzzzzz

in index.php you have commented out some of the pagination code.

uncomment those lines and see how you go.

I copied and pasted my original posted code back onto my pc to double check that it works and it works without problems.

if you change anything apart from the input parameters in index.php don’t post back saying my code doesn’t work properly because after you change it by commenting out things you shouldn’t, it then becomes your code and not mine.

<?php
require_once('upper.php');
//require_once('database.php');
//$dbc=mysql_connect('localhost','root','','nog') or die('Not Connected');
session_start();
//----------------------------------------------------------------------------------------------------------------------
//connect to the database
$DBUserName = "root"; //database user account name
$DBPassword = ""; //database user account password
$DBName = "nog"; //name of database
 
$conn = mysql_connect("localhost",$DBUserName,$DBPassword) or die('<br />1-Cannot connect to the database at the moment.<br /><br />Please try again later.<br />'); //connect to mysql
$isDbSelected = mysql_select_db($DBName, $conn) or die('<br />1-Cannot connect to the database at the moment.<br /><br />Please try again later.<br />'); //connect to the db
//----------------------------------------------------------------------------------------------------------------------
include('paginator.php');
if(!isset($_SESSION['pageMaker'])) {

$linesPerPage = 3; //number of lines to print per page
$numLinksDisplay = 5; //number of page links to display at a time
$dbTable = 'events'; //database table to page results
$tableCols = array('*'); //array of column names of records to be retrieved
$pageMaker = new paginator($linesPerPage,$numLinksDisplay,$dbTable,$tableCols,$conn);}

else {
$pageMaker = unserialize($_SESSION['pageMaker']);
}

//set current page
if(isset($_GET['type'])) $pageMaker->setCurrPage($_GET['type'],$_GET['txtPgNum']);

//------------------------------------------------------------
//Code to retrieve the rows to display on the current page
//------------------------------------------------------------
if(!$rs = $pageMaker->getPageRecords($conn)) die('<p>**ERROR - cannot get records for the page at the moment.</p>');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Events</title>
<!-- add the stylesheet for the page links -->
<?php echo $pageMaker->getLinkStyles(); ?>
</head>
<body>
<!-- Display the page links -->
<div id="page_links_wrapper">
<?php $pageMaker->showLinks(); ?>
</div>
<!-- Code block to display the DB records for this page-->
<table>
<?php
while($row=mysql_fetch_assoc($rs)) {

$Title=$row['Title'];
$City=$row['City'];
$Content=$row['Content'];
//$Photo=$row['Photo'];
$Date=$row['Date'];
$EventId=$row['EventId'];
$Photo=$row['Photo'];
//echo $Photo;

echo    "<div><table border='0' cellspacing='0' cellpadding='0' width='389'>
            <tr>
                <td><img src='images/events_2.png' width='389' height='10'></td>
            </tr>
            
            <tr>
                <td background='images/events_2_bg.png'>
                    <table border='0' cellspacing='0' width='359'>
                        <tr>
                                    
                            <td>
                                <tr>
                                    <table width='100%' border='0' cellspacing='0' >
                                        <tr>
                                            <td rowspan='3'><img src='$Photo' width='80' height='60'></td>            
                                            <td align='left' valign='top' width='180'>$City</td>
                                            <td align='left' valign='top'>$Date</td>                                            
                                        </tr>
                                        <tr>                                            
                                            <td colspan='3' align='left' valign='top'>$Title</td>                        
                                            
                                        </tr>
                                        <tr>
                                            <td colspan='2'><a href='KnowMore.php?EventId=".$row['EventId']."'>Know more </a> / <a href='EventParticipator.php?EventId=".$row['EventId']."'>click here to participate</a></td>
                                        </tr>
                                        
                                    </table>
                                </tr>
                            
                        </tr>    
                    </table>                    
                </td>
            </tr>
            
            <tr>
                <td><img src='images/events_2_bottom.png' width='389' height='10' ></td>
            </tr>
            
        </table></div>";

//echo '<tr><td>'.$row['fldPersonID'].'</td><td>'.$row['fldGivenName'].'</td><td>'.$row['fldFamilyName'].'</td></tr>';
}
mysql_free_result($rs);
mysql_close($conn);

?>
</table>
<!-- End of code block to display the DB records for this page-->
<?php
//hide or display the 'previous' and 'next' buttons as required
$pageMaker->applyLinkStyles();
//serialise the session's pageMaker object for the next call to this page
$_SESSION['pageMaker'] = serialize($pageMaker);
require_once('lower.php');
?>
</body>
</html>

Sorry sir but when I commenting session attribute then I got
[B]Notice: Undefined index: Title in C:\wamp\www\NGOProject\Elite Brigade\EventDisplaypp.php on line 55

Notice: Undefined index: City in C:\wamp\www\NGOProject\Elite Brigade\EventDisplaypp.php on line 56

Notice: Undefined index: Content in C:\wamp\www\NGOProject\Elite Brigade\EventDisplaypp.php on line 57

Notice: Undefined index: Date in C:\wamp\www\NGOProject\Elite Brigade\EventDisplaypp.php on line 59[/B] errors.

I don’t know wht is going wrong.

neither do I.

you have added a require_once() file in your code. the errors might be related to the code in that file.

Kalon post 4 and 11 working perfect per single table that mean I am using two tables I posting my sql table here.


CREATE TABLE `ca_models` (

`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`category` varchar(50) NOT NULL default 'General',
`time` varchar(60) default NULL,
`name` VARCHAR( 50 ) NOT NULL ,
`email` VARCHAR( 40 ) NOT NULL ,
`age` VARCHAR( 2 ) NOT NULL ,
`public` char(3) NOT NULL default 'no',
`image` VARCHAR( 50 ) NOT NULL 

) ENGINE = MYISAM ;

CREATE TABLE `model_category` (
  `id` int(4) unsigned NOT NULL auto_increment,
  `name` varchar(50) default NULL,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

when select category list. I get data from the ca_models.( category wise)

this is my categorylist.php


&lt;a href="index.php?category=Indian Male Models"&gt;Indian Male Models&lt;/a&gt;
&lt;a href="index.php?category=Indian Female Models"&gt;Indian  Female Models&lt;/a&gt; 

index.php


actual code
$query = 'select * from tblperson';

to 

$query ='SELECT * FROM ca_models  WHERE category = ".$name." and public = "yes" '

the post 11 shoot for my thoughts but i can not understanding how can used for two tables

kolan are u understanding my explanation

once again thank U…

kolan…!! :lol: :slight_smile:

anyway, now that I’ve stopped laughing unfortunately it’s not clear to me what you want to do exactly with 2 tables :frowning:

Basically, all you need to do is build your query like you would for anything else and then pass it to $query in index.php from post 11.

Hopefully it will be clearer if you list which columns from your 2 tables you want to display on your page and which column in either table is a foreign key and which column is it referencing.

But a couple of suggestions:

  1. in your link it might be safer to use a category id as the value of the category parameter rather than a string. but if you must use a string you should [FPHP]urlencode[/FPHP] it.

  2. I think

 
$query [COLOR=#007700]=[/COLOR][COLOR=#dd0000]'SELECT * FROM ca_models  WHERE category = ".$name." and public = "yes" ';[/COLOR]

should be

 
$query [COLOR=#007700]=[/COLOR][COLOR=#dd0000]'SELECT * FROM ca_models  WHERE category = "'.$name.'" and public = "yes" ';[/COLOR]

Really sorry about my mistake…

I added this one
$name = addslashes(strip_tags($_GET[‘category’]));
finally getting data perfectly

But

First page showing data correctly. and other pages 2,3,4… showing blank pages what is the problem