0

除了 tsql 过滤器在有页面切换时重置之外,一切都在分页模板上完美运行。

    session_start(); // initiate session




$conn = getConnection();
/*
    Place code to connect to your DB here.
*/
include('config.php');  // include your code to connect to DB.



$tbl_name="vwJobWantedListing";     //your table name
// How many adjacent pagers 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(isset($_POST['search'])){
    $_SESSION['s_salary']= osc_esc_html( $_REQUEST['s_salary'] );
    $_SESSION['s_educ01']= osc_esc_html( $_REQUEST['s_educ01'] );

    $query = sprintf( "SELECT COUNT(*) as num FROM $tbl_name WHERE s_educ01='%s'",$_SESSION['s_educ01'] ) ;
    //echo $query;


}else {
    $_SESSION['s_salary']='-1';
    $_SESSION['s_educ01']='--Select--';

    $query = "SELECT COUNT(*) as num FROM $tbl_name ";
}

$query = sprintf( "SELECT COUNT(*) as num FROM $tbl_name WHERE s_educ01='%s'",$_SESSION['s_educ01'] ) ;
$_SESSION['sql_cnt']=$query ;



$total_pagers = mysql_fetch_array(mysql_query( $_SESSION['sql_cnt'] ));
$total_pagers = $total_pagers[num];

/* Setup vars for query. */
$targetpager = "index.php?page=custom&file=profile_cv/list_wanted.php";     //your file name  (the name of this file)
$limit = 5;                                 //how many items to show per pager
$pager = $_GET['pager'];
if($pager) 
    $start = ($pager - 1) * $limit;             //first item to display on this pager
else
    $start = 0;                             //if no pager var is given, set start to 0

/* Get data. */

if(isset($_POST['search'])){

    $sql = "SELECT * FROM $tbl_name WHERE s_educ01='".  $_SESSION['s_educ01']. "' LIMIT $start, $limit" ;
}else{

    $sql =    "SELECT * FROM $tbl_name LIMIT $start, $limit";
}


$_SESSION['sql_src']=$sql;

$result = mysql_query($_SESSION['sql_src']);


/* Setup pager vars for display. */
if ($pager == 0) $pager = 1;                    //if no pager var is given, default to 1.
$prev = $pager - 1;                         //previous pager is pager - 1
$next = $pager + 1;                         //next pager is pager + 1
$lastpager = ceil($total_pagers/$limit);        //lastpager is = total pagers / items per pager, rounded up.
$lpm1 = $lastpager - 1;                     //last pager 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($lastpager > 1)
{   
    $pagination .= "<div class=\"pagination\">";
    //previous button
    if ($pager > 1) 
        $pagination.= "<a href=\"$targetpager?pager=$prev\"> previous</a>";
    else
        $pagination.= "<span class=\"disabled\"> previous</span>";  

    //pagers    
    if ($lastpager < 7 + ($adjacents * 2))  //not enough pagers to bother breaking it up
    {   
        for ($counter = 1; $counter <= $lastpager; $counter++)
        {
            if ($counter == $pager)
                $pagination.= "<span class=\"current\">$counter</span>";
            else
                $pagination.= "<a href=\"$targetpager?pager=$counter\">$counter</a>";                   
        }
    }
    elseif($lastpager > 5 + ($adjacents * 2))   //enough pagers to hide some
    {
        //close to beginning; only hide later pagers
        if($pager < 1 + ($adjacents * 2))       
        {
            for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
            {
                if ($counter == $pager)
                    $pagination.= "<span class=\"current\">$counter</span>";
                else
                    $pagination.= "<a href=\"$targetpager?pager=$counter\">$counter</a>";                   
            }
            $pagination.= "...";
            $pagination.= "<a href=\"$targetpager?pager=$lpm1\">$lpm1</a>";
            $pagination.= "<a href=\"$targetpager?pager=$lastpager\">$lastpager</a>";       
        }
        //in middle; hide some front and some back
        elseif($lastpager - ($adjacents * 2) > $pager && $pager > ($adjacents * 2))
        {
            $pagination.= "<a href=\"$targetpager?pager=1\">1</a>";
            $pagination.= "<a href=\"$targetpager?pager=2\">2</a>";
            $pagination.= "...";
            for ($counter = $pager - $adjacents; $counter <= $pager + $adjacents; $counter++)
            {
                if ($counter == $pager)
                    $pagination.= "<span class=\"current\">$counter</span>";
                else
                    $pagination.= "<a href=\"$targetpager?pager=$counter\">$counter</a>";                   
            }
            $pagination.= "...";
            $pagination.= "<a href=\"$targetpager?pager=$lpm1\">$lpm1</a>";
            $pagination.= "<a href=\"$targetpager?pager=$lastpager\">$lastpager</a>";       
        }
        //close to end; only hide early pagers
        else
        {
            $pagination.= "<a href=\"$targetpager?pager=1\">1</a>";
            $pagination.= "<a href=\"$targetpager?pager=2\">2</a>";
            $pagination.= "...";
            for ($counter = $lastpager - (2 + ($adjacents * 2)); $counter <= $lastpager; $counter++)
            {
                if ($counter == $pager)
                    $pagination.= "<span class=\"current\">$counter</span>";
                else
                    $pagination.= "<a href=\"$targetpager?pager=$counter\">$counter</a>";                   
            }
        }
    }

    //next button
    if ($pager < $counter - 1) 
        $pagination.= "<a href=\"$targetpager?pager=$next\">next </a>";
    else
        $pagination.= "<span class=\"disabled\">next </span>";
    $pagination.= "</div>\n";       
}

我厌倦了会话来保存数据过滤器变量,但是当页面移动时,重置总是发生。

任何想法将不胜感激。

4

1 回答 1

0

您将源查询存储在会话中,$_SESSION['sql_src']=$sql;但您从未在后续请求中检查它。

尝试:

if(isset($_POST['search'])){
    $sql = "SELECT * FROM $tbl_name WHERE s_educ01='".  $_SESSION['s_educ01']. "' LIMIT $start, $limit" ;
}else{
    if(isset($_SESSION['sql_src'])){
         $sql = $_SESSION['sql_src']; 
    }else{
        $sql =    "SELECT * FROM $tbl_name LIMIT $start, $limit";
    }
}

更新:

再次阅读您的代码后,我可以看到您只是在 POST 上进行搜索。只有您的初始请求将是 POST,所有其他请求(通过单击寻呼机)将是 GET。上面的代码确实说明了这一点。

于 2013-10-29T12:26:45.093 回答