Hello,
I have a script, it displays all active banners using pagination. Once the banner is clicked it doesn’t show up again. This works fine.
The issue:
For example I’m displaying 25 banners per page, I have over 1000 active banners so there are 102 pages.
If I click on the all 25 of the banners on page one and then leave the site, the next time I come back to the site they do not show. This works correctly. But here is the problem, when I come back to the site page one is blank, I have to move on to page 2 in order to see the next round of banners. So in other words it’s not moving the banners up to page one.
I need this fixed.
Here is the code if you think you want to tackle it.
[code]
<?php
session_start();
include "../header.php";
include "../config.php";
include "../style.php";
$uname=$_SESSION[uname];
if( session_is_registered("ulogin") ) {
$tbl_name="banners"; //your table name
// How many adjacent pages should be shown on each side?
$adjacents = 3;
/*
First get total number of rows in data table.
If you have a WHERE clause in your query, make sure you mirror it here.
*/
if( session_is_registered("ulogin") )
{
$query = "SELECT COUNT(*) as num FROM banners, banner_clicks WHERE banners.status=1 and banners.max>banners.shown AND banner_clicks.userid<>'".userid."' group by banners.id";
}
else
$query = "SELECT COUNT(*) as num FROM $tbl_name WHERE status=1 and max>shown";
$ttlpag=mysql_query($query) or die (mysql_error());
$total_pages = mysql_fetch_array($ttlpag);
$total_pages = $total_pages[num];
$qn="select * from sat_banclicks where userid='$uname' group by bannerid";
$ns=mysql_query($qn);
$nk=mysql_num_rows($ns);
$total_pages=$total_pages-(2*$nk);
//echo $nk;
/* Setup vars for query. */
$targetpage = "bannerlinkview.php"; //your file name (the name of this file)
$limit = 25; //how many items to show per page
$page = $_GET['page'];
if($page)
$start = ($page - 1) * $limit; //first item to display on this page
else
$start = 1; //if no page var is given, set start to 0
/* Get data. */
if( session_is_registered("ulogin") )
{
$sql = "SELECT banners.id as id, banners.name as name, banners.bannerurl as bannerurl, banners.targeturl as targeturl, banners.userid as userid, banners.shown as shown, banners.clicks as clicks, banners.max as max, banners.added as added FROM banners, banner_clicks WHERE banners.status=1 and banners.max>banners.shown AND banner_clicks.userid<>'".userid."' group by banners.id LIMIT $start, $limit";
}
else
{
$sql = "SELECT * FROM banners WHERE status=1 and max>shown LIMIT $start, $limit";
}
$result = mysql_query($sql) or die (mysql_error());
if(!mysql_num_rows($result))
{
$result = mysql_query ("SELECT * FROM banners WHERE status=1 and max>shown LIMIT $start, $limit");
}
/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class="pagination">";
//previous button
if ($page > 1)
$pagination.= "<a href="$targetpage?page=$prev">