Jump to content

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";
}
}
?>

I tired did everything right and it doesn't work

If you did it right, it would work...  What about it doesn't work?

 

I feel like i did it right, on my first tries i was getting errors now im not after i worked on it. Do you see any problems?

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.