Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.