0
<?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???????

3
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by mafhh14
0
<?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');
?>

I did not understand what you exactly required. But I hope the given link helps you to make pagination http://www.phpmoot.com/php-pagination/

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.