Jump to content

page counter


freshteh

Recommended Posts

if you are after a pages system. i have made an easy way.

 

Here is the codes::

 

creat a file called pages.php and past the following in it :

 

<!-- A header should be here so that the text works  -->
<?php
echo "<div align=center>";
$display = 20;


if (isset($_REQUEST["np"]))
{
$num_pages = $_REQUEST["np"];
}
else
{
$query2 =  "SELECT COUNT(*) FROM $table $whereCond $whereCond2 ORDER BY $orderBy $asc_desc" or die("oh dear" . mysql_error());
$result2 = mysql_query($query2);
$row2 = mysql_fetch_array($result2, MYSQL_NUM);
$num_records = $row2[0];
}

if ($num_records > $display) 
{
$num_pages = ceil ($num_records/$display);
}
else
{
$num_pages = 1;
}

if (isset($_GET["s"]))
{
$start = $_GET["s"];
}
else
{
$start = 0;
}

if ($num_pages > 1)
{
$current_page = ($start/$display) + 1;
if ($current_page != 1) 
	{
		echo "<a href=\"?s=" . ($start - $display) . "&w=" . $find . "\">Previous</a> ";
	}

for ($i = 1; $i <= $num_pages; $i++)
{
	if($i != $current_page)
	{
		echo "<a href=\"?s=" . ($display * ($i - 1)) . "&w=" . $find . "\">" . $i . "</a> ";
	}
	else
	{
		echo $i . " ";
	}
}
if ($current_page != $num_pages)
{
	echo "<a href=\"?s=" . ($start + $display) . "&w=" . $find . "\">Next</a>";
}
}
echo "</div><br />";
?>	

 

then where you want your pages past this code::

 


$table = "t1";
$whereCond = ""; //WHERE xxxx = 'xxxx';
$whereCond2 = ""; //AND/OR xxxx = 'xxxx';
$orderBy = "";
$asc_desc = "";


$result = mysql_query("SELECT * FROM $table $whereCond $whereCond2 ORDER BY $orderBy $asc_desc LIMIT $start, $display")or die(mysql_error());

 

Hope this helps...

Link to comment
https://forums.phpfreaks.com/topic/85354-page-counter/#findComment-435504
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.