astonishin Posted June 24, 2011 Share Posted June 24, 2011 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/240271-how-can-i-add-simple-pagination-here/ Share on other sites More sharing options...
QuickOldCar Posted June 24, 2011 Share Posted June 24, 2011 Pagination is never simple, here's a tutorial here. http://www.phpfreaks.com/tutorial/basic-pagination Quote Link to comment https://forums.phpfreaks.com/topic/240271-how-can-i-add-simple-pagination-here/#findComment-1234183 Share on other sites More sharing options...
astonishin Posted June 24, 2011 Author Share Posted June 24, 2011 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\">«prev</a>"; else $pagination.= "<span class=\"disabled\">«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»</a>"; else $pagination.= "<span class=\"disabled\">next»</span>"; $pagination.= "</div>\n"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/240271-how-can-i-add-simple-pagination-here/#findComment-1234327 Share on other sites More sharing options...
Maq Posted June 24, 2011 Share Posted June 24, 2011 I tired did everything right and it doesn't work If you did it right, it would work... What about it doesn't work? Quote Link to comment https://forums.phpfreaks.com/topic/240271-how-can-i-add-simple-pagination-here/#findComment-1234367 Share on other sites More sharing options...
astonishin Posted June 24, 2011 Author Share Posted June 24, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/240271-how-can-i-add-simple-pagination-here/#findComment-1234408 Share on other sites More sharing options...
astonishin Posted June 26, 2011 Author Share Posted June 26, 2011 Where am i suppose to include the pagination? Quote Link to comment https://forums.phpfreaks.com/topic/240271-how-can-i-add-simple-pagination-here/#findComment-1234864 Share on other sites More sharing options...
Clandestinex337 Posted June 26, 2011 Share Posted June 26, 2011 http://youtu.be/wd4fE5fk-fk Quote Link to comment https://forums.phpfreaks.com/topic/240271-how-can-i-add-simple-pagination-here/#findComment-1234868 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.