Jump to content

How Can I add Simple Pagination Here?


astonishin

Recommended Posts

How can i add pagination to this

 

<?php

session_start();
global $ui,$count;
$page = "offers";
include("assets/includes/connect.php");
include("assets/includes/config.php");

if($_SESSION['loggedin'] != 1){

	echo "<font color='red'>Sorry, you must be logged in to view this page.</font>";
	include("assets/footer.php");
	exit();

}
	echo "<center><div class='header-orange'><a href='?os=completed'>".$ui['username']." Completed Offers</a></div></center>";
	echo "<center>Please select an offer category.</center>";
	echo "<center>";

		$get = mysql_query("SELECT * FROM `offer_types` WHERE `active` = '1'") or die(mysql_error());
		if(mysql_num_rows($get) == 0){

			echo "";

		} else {

			while($row = mysql_fetch_array($get)){

				echo "<div class='memc'><a href='http://www.mucove.com/?os=offers&type=" . $row['id'] . "'>" . $row['type'] . "</a></div>  ";

			}

			echo "<br /><br />";

			if($_GET['type']){

				$sql = mysql_query("SELECT * FROM `offers` WHERE `active` = '1' AND `type` = '" . mysql_real_escape_string($_GET['type']) . "'") or die(mysql_error());

			} else {

				$sql = mysql_query("SELECT * FROM `offers` WHERE `active` = '1'") or die(mysql_error());

			}

			if(mysql_num_rows($sql) == 0){

				echo "<font color='red'>Sorry, there are no campaigns availble at this time.</font>";

			} else {

				while($row = mysql_fetch_array($sql)){

					echo "<div class='offerc'><table width='100%'>";
					echo "<tr>";
					echo "<td><a href='http://www.mucove.com/?os=track&campaign=" . $row['id'] . "' target='_blank'>" . $row['name'] . "</a><font style='float: right; font-weight: bold;'>$" . $row['reward'] . "</font><br /><font style='size: 12px;'><i>" . $row['info'] . "</i></font></td>";
					echo "</tr>";
					echo "</table></div><br /><br />";

				}

			}

		}

	echo "</center>";

?>

Link to comment
https://forums.phpfreaks.com/topic/240271-how-can-i-add-simple-pagination-here/
Share on other sites

I tired did everything right and it doesn't work

 

<?php
session_start();
$adjacents = 3;
$query = "SELECT * FROM `offer_types` WHERE `active` = '1'";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[0];
$limit = 15;
$page = $_GET['page'];
if($page)
{
$start = ($page - 1) * $limit;
}
else
{
$start = 0;
if ($page == 0) $page = 1;
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$lpm1 = $lastpage - 1;
$pagination = "";
if($lastpage > 1)
{
	$pagination .= "<div class=\"pagination\">";
	if ($page > 1)
		$pagination.= "<a href=\"?os=offers&type="  . $row['type'] . "&page=$prev\">&#171;prev</a>";
	else
		$pagination.= "<span class=\"disabled\">&#171;prev</span>";

	if ($lastpage < 7 + ($adjacents * 2))
	{
		for ($counter = 1; $counter <= $lastpage; $counter++)
		{
			if ($counter == $page)
				$pagination.= "<span class=\"current\"> |".$counter."| </span>";
			else
				$pagination.= "<a href=\"?os=offers&type="  . $row['type'] . "&page=$counter\"> |".$counter."| </a>";
		}
	}
	elseif($lastpage > 5 + ($adjacents * 2))
	{

		if($page < 1 + ($adjacents * 2))
		{
			for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\"> |".$counter."| </span>";
				else
					$pagination.= "<a href=\"?os=offers&type="  . $row['type'] . "&page=$counter\"> |".$counter."| </a>";
			}
			$pagination.= "...";
			$pagination.= "<a href=\"?os=offers&type="  . $row['type'] . "&page=$lpm1\"> |".$lpm1."| </a>";
			$pagination.= "<a href=\"?os=offers&type="  . $row['type'] . "&page=$lastpage\"> |".$lastpage."| </a>";
		}
		elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
		{
			$pagination.= "<a href=\"?os=offers&type="  . $row['type'] . "&page=1\"> |1| </a>";
			$pagination.= "<a href=\"?os=offers&type="  . $row['type'] . "&page=2\"> |2| </a>";
			$pagination.= "...";
			for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\"> |".$counter."| </span>";
				else
					$pagination.= "<a href=\"?os=offers&type="  . $row['type'] . "&page=$counter\"> |".$counter."| </a>";
			}
			$pagination.= "...";
			$pagination.= "<a href=\"?os=offers&type="  . $row['type'] . "&page=$lpm1\"> |".$lpm1."| </a>";
			$pagination.= "<a href=\"?os=offers&type="  . $row['type'] . "&page=$lastpage\"> |".$lastpage."| </a>";
		}
		else
		{
			$pagination.= "<a href=\"?os=offers&type="  . $row['type'] . "&page=1\"> |1| </a>";
			$pagination.= "<a href=\"?os=offers&type="  . $row['type'] . "&page=2\"> |2| </a>";
			$pagination.= "...";
			for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\"> |".$counter."| </span>";
				else
					$pagination.= "<a href=\"?os=offers&type="  . $row['type'] . "&page=$counter\"> |".$counter."| </a>";
			}
		}
	}

	if ($page < $counter - 1)
		$pagination.= "<a href=\"?os=offers&type="  . $row['type'] . "&page=$next\">next&#187;</a>";
	else
		$pagination.= "<span class=\"disabled\">next&#187;</span>";
	$pagination.= "</div>\n";
}
}
?>

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.