分页和 php 会话变量

发布于 2024-12-19 02:18:26 字数 8425 浏览 0 评论 0原文

我这里只有一个简单的问题:

我正在为我的网站开发新闻存档页面,对存档的搜索是通过开始日期、结束日期和新闻类别作为搜索参数来完成的。表单值存储在 $_SESSION var 中,然后将它们作为数组传递以用于分页和其他目的。 我的问题是,如果用户出于某种原因再次访问主存档搜索页面进行新搜索,如何防止在主存档搜索页面上显示搜索结果。

这是代码

<?php 
session_start();
if (isset($_POST['submit'])) {
    //get data from the form
    $archFld_1 = $_POST['archiveFld1'];
    $archFld_2 = $_POST['archiveFld2'];
    $archFld_3 = $_POST['archiveFld3'];
   //just some check on fields
   if (strlen($archFld_1) > 10) { $archFld_1 = ""; }
   if (strlen($archFld_2) > 10) { $archFld_2 = ""; }
   //save them as a array and store to session var
   $_archValues = array($archFld_3, $archFld_1, $archFld_2);
   $_SESSION['storeValues'] = $_archValues;
}
if (isset($_SESSION['storeValues'])) {
    //check params for search
    //set cat for query
    if ($_SESSION['storeValues'][0] > 0) { $valCat = "AND newsCat=".     $_SESSION['storeValues'][0] ." "; } else { $valCat = ""; }
    //set date for query
    if(($_SESSION['storeValues'][1] != "" ) && ($_SESSION['storeValues'][2] == "")) {
        $DateStart = $_SESSION['storeValues'][1];
        $valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') >= STR_TO_DATE('$DateStart', '%d-%m-%Y') ";
    }
    if(($_SESSION['storeValues'][2] != "") && ($_SESSION['storeValues'][1]=="")) {
        $DateEnd = $_SESSION['storeValues'][2];
        $valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') <= STR_TO_DATE('$DateEnd', '%d-%m-%Y') ";
    }
    if(($_SESSION['storeValues'][1]!="") && ($_SESSION['storeValues'][2] != "")) {
        $DateStart = $_SESSION['storeValues'][1];
        $DateEnd = $_SESSION['storeValues'][2];
        $valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') BETWEEN STR_TO_DATE('$DateStart', '%d-%m-%Y') AND STR_TO_DATE('$DateEnd', '%d-%m-%Y') ";
    }
    //query string and stire it to session
    $archQuery_string = $valCat.$valDate;
    $_SESSION['storeQuery'] = $archQuery_string;
}
//pagination start
$page = $_GET['id'];
$perPage = 10;
$result = wbQuery("SELECT * FROM wb_news WHERE newsLang=1 ". $_SESSION["storeQuery"] ."ORDER BY newsId DESC"); 
$totalPages = mysql_num_rows($result);
if(!$page)
$page = 1;
$start = ($page - 1)*$perPage;
?>
    <div id="sps_middle">
        <div class="sps_cnt">
            <div id="sps_middle_ly1">
                <div class="sps_cnt_small">
                    <div class="sps_page_title"><h3><?php echo $wb_lng['txtArchiveTitle']; ?></h3></div>
                        <div class="sps_pages_cnt" style="padding-top: 10px; float: left; margin-bottom: 15px;">
                            <div class="sps_middle_col01">
                                <div style="float: left;">
                                <p>
                                    <?php echo $wb_lng['txtArchiveInfo']; ?>
                                </p>
                                    <form action="<?php $PHP_SELF; ?>" method="post" name="archiveForm" class="archiveForm">
                                        <ul>
                                            <li>
                                                <input name="archiveFld1" type="text" id="archiveFld1" value="<?php echo $wb_lng['txtArhivaFld_01']; ?>" />
                                                <input name="archiveFld2" type="text" id="archiveFld2" value="<?php echo $wb_lng['txtArhivaFld_02']; ?>" />
                                                <select name="archiveFld3">
                                                    <option value="0"><?php echo $wb_lng['txtArhivaFld_07']; ?></option>
                                                    <option value="0" ><?php echo $wb_lng['txtArhivaFld_06']; ?></option>
                                                    <option value="1"><?php echo $wb_lng['txtArhivaFld_03']; ?></option>
                                                    <option value="2"><?php echo $wb_lng['txtArhivaFld_04']; ?></option>
                                                    <option value="3"><?php echo $wb_lng['txtArhivaFld_05']; ?></option>
                                                </select>
                                            </li>
                                            <li style="float: right;">
                                                <input name="reset" type="reset" class="sps_archiveform_btn" value="<?php echo $wb_lng['txtArchiveFormReset']; ?>"/>
                                                <input name="submit" type="submit" class="sps_archiveform_btn" value="<?php echo $wb_lng['txtArchiveFormSend']; ?>"/>
                                            </li>
                                        </ul>
                                    </form>
                                </div>
                                <hr />
<?php
if (#HERE GOES SOME CODE TO PERFORM THE CHECK!!!#) {
    //perform db query
    $result = wbQuery("SELECT * FROM wb_news WHERE newsLang=1 ". $_SESSION['storeQuery'] ."ORDER BY newsId DESC LIMIT $start, $perPage"); 
    //count rows
    $totalnews = mysql_num_rows($result);
    $count = 1;
    if($totalnews == 0) {
        //no results, say to the user
        echo "\t\t\t<div class=\"cil_news_text_big\">\n\t\t\t\t".$wb_lng['txtArchiveNoEntries']."\n\t\t\t</div>\n";
    } else {
        //we have results, yeeeeeeeeey
        while($ROWnews = mysql_fetch_object($result)){
            //set link extensions by the news cat
            switch ($ROWnews->newsCat) {
                case 1:
                    $newsCat_link = "news";
                    break;
                case 2:
                    $newsCat_link = "statements";
                    break;
                case 3:
                    $newsCat_link = "events";
                    break;
            }
            //text summary
            if (strlen($ROWnews->newsShort) > 0 ) {$newsShortTxt = strip_tags($ROWnews->newsShort);
                if ($lang_id==2) { $newsShortTxt =  wbTranslit($newsShortTxt); }
            } else {
                $newsShortTxt = strip_tags($ROWnews->newsFull);
                if ($lang_id==2) { $newsShortTxt = wbTranslit($newsShortTxt); }
            }
            $newsShortTxt = wbShorTxt($newsShortTxt, 210, "... <a title=\"".$wb_lng['txtShowMore']."\" href=\"http://".$_SERVER['HTTP_HOST']."/".$lang_link."/".$newsCat_link."/".$ROWnews->newsId."/full/\">".$wb_lng['txtShowMore']."...</a>");
            //show news
            echo "\t\t<div class=\"sps_news_list\">\n";
            echo "\t\t<div class=\"sps_news_l\">\n";
            echo "\t\t\t<img alt=\"\" src=\"http://".$_SERVER['HTTP_HOST']."/content/images/news/_thumb/".$ROWnews->newsImageThumb."\" />\n";
            echo "\t\t</div>";
            echo "\t\t<div class=\"sps_news_r\">\n";
            //transliterate title
            if ($lang_id==2) { $newsTitle =  wbTranslit($ROWnews->newsTitle); } else { $newsTitle =  $ROWnews->newsTitle; } 
            echo "\t\t\t<div class=\"sps_news_title\">\n\t\t\t\t<a title=\"".$newsTitle."\" href=\"http://".$_SERVER['HTTP_HOST']."/".$lang_link."/".$newsCat_link."/".$ROWnews->newsId."/full/\">".$newsTitle."</a>\n\t\t\t</div>\n";
            echo "\t\t\t<div class=\"sps_news_date\">\n\t\t\t\t".$ROWnews->newsDate."\n\t\t\t</div>\n";
            echo "\t\t\t<div class=\"sps_news_text_sh\">\n\t\t\t\t".$newsShortTxt."\n\t\t\t</div>\n";
            echo "\t\t</div>";
            echo "\t\t</div>";
            //show <hr /> based on $count
            if($totalnews != $count) { echo "\t\t\t<hr />\n"; }
            $count++;
        }
    }
//pagination check
if($totalPages>$perPage) {
?>
                                <hr />
                                <div class="sps_pagginate">
                                   <?PHP wbPageTurnFront($PHP_SELF."/".$lang_link."/archive/", $totalPages, $page, $perPage); ?>
                                </div>
<?php 
    }
}
?>

有什么想法吗? 恩克斯 :)

I just have one simple question here is the desc:

I'm working on news archive page for my website, search over archive is done with start date, end date and news category as search parameters. Form values are stored in $_SESSION var, and then they are passed around as an array for pagination and other purposes.
My question would be how to prevent displaying search results on main archive search page if user for some reason goes again to it to make a new search.

here's the code

<?php 
session_start();
if (isset($_POST['submit'])) {
    //get data from the form
    $archFld_1 = $_POST['archiveFld1'];
    $archFld_2 = $_POST['archiveFld2'];
    $archFld_3 = $_POST['archiveFld3'];
   //just some check on fields
   if (strlen($archFld_1) > 10) { $archFld_1 = ""; }
   if (strlen($archFld_2) > 10) { $archFld_2 = ""; }
   //save them as a array and store to session var
   $_archValues = array($archFld_3, $archFld_1, $archFld_2);
   $_SESSION['storeValues'] = $_archValues;
}
if (isset($_SESSION['storeValues'])) {
    //check params for search
    //set cat for query
    if ($_SESSION['storeValues'][0] > 0) { $valCat = "AND newsCat=".     $_SESSION['storeValues'][0] ." "; } else { $valCat = ""; }
    //set date for query
    if(($_SESSION['storeValues'][1] != "" ) && ($_SESSION['storeValues'][2] == "")) {
        $DateStart = $_SESSION['storeValues'][1];
        $valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') >= STR_TO_DATE('$DateStart', '%d-%m-%Y') ";
    }
    if(($_SESSION['storeValues'][2] != "") && ($_SESSION['storeValues'][1]=="")) {
        $DateEnd = $_SESSION['storeValues'][2];
        $valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') <= STR_TO_DATE('$DateEnd', '%d-%m-%Y') ";
    }
    if(($_SESSION['storeValues'][1]!="") && ($_SESSION['storeValues'][2] != "")) {
        $DateStart = $_SESSION['storeValues'][1];
        $DateEnd = $_SESSION['storeValues'][2];
        $valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') BETWEEN STR_TO_DATE('$DateStart', '%d-%m-%Y') AND STR_TO_DATE('$DateEnd', '%d-%m-%Y') ";
    }
    //query string and stire it to session
    $archQuery_string = $valCat.$valDate;
    $_SESSION['storeQuery'] = $archQuery_string;
}
//pagination start
$page = $_GET['id'];
$perPage = 10;
$result = wbQuery("SELECT * FROM wb_news WHERE newsLang=1 ". $_SESSION["storeQuery"] ."ORDER BY newsId DESC"); 
$totalPages = mysql_num_rows($result);
if(!$page)
$page = 1;
$start = ($page - 1)*$perPage;
?>
    <div id="sps_middle">
        <div class="sps_cnt">
            <div id="sps_middle_ly1">
                <div class="sps_cnt_small">
                    <div class="sps_page_title"><h3><?php echo $wb_lng['txtArchiveTitle']; ?></h3></div>
                        <div class="sps_pages_cnt" style="padding-top: 10px; float: left; margin-bottom: 15px;">
                            <div class="sps_middle_col01">
                                <div style="float: left;">
                                <p>
                                    <?php echo $wb_lng['txtArchiveInfo']; ?>
                                </p>
                                    <form action="<?php $PHP_SELF; ?>" method="post" name="archiveForm" class="archiveForm">
                                        <ul>
                                            <li>
                                                <input name="archiveFld1" type="text" id="archiveFld1" value="<?php echo $wb_lng['txtArhivaFld_01']; ?>" />
                                                <input name="archiveFld2" type="text" id="archiveFld2" value="<?php echo $wb_lng['txtArhivaFld_02']; ?>" />
                                                <select name="archiveFld3">
                                                    <option value="0"><?php echo $wb_lng['txtArhivaFld_07']; ?></option>
                                                    <option value="0" ><?php echo $wb_lng['txtArhivaFld_06']; ?></option>
                                                    <option value="1"><?php echo $wb_lng['txtArhivaFld_03']; ?></option>
                                                    <option value="2"><?php echo $wb_lng['txtArhivaFld_04']; ?></option>
                                                    <option value="3"><?php echo $wb_lng['txtArhivaFld_05']; ?></option>
                                                </select>
                                            </li>
                                            <li style="float: right;">
                                                <input name="reset" type="reset" class="sps_archiveform_btn" value="<?php echo $wb_lng['txtArchiveFormReset']; ?>"/>
                                                <input name="submit" type="submit" class="sps_archiveform_btn" value="<?php echo $wb_lng['txtArchiveFormSend']; ?>"/>
                                            </li>
                                        </ul>
                                    </form>
                                </div>
                                <hr />
<?php
if (#HERE GOES SOME CODE TO PERFORM THE CHECK!!!#) {
    //perform db query
    $result = wbQuery("SELECT * FROM wb_news WHERE newsLang=1 ". $_SESSION['storeQuery'] ."ORDER BY newsId DESC LIMIT $start, $perPage"); 
    //count rows
    $totalnews = mysql_num_rows($result);
    $count = 1;
    if($totalnews == 0) {
        //no results, say to the user
        echo "\t\t\t<div class=\"cil_news_text_big\">\n\t\t\t\t".$wb_lng['txtArchiveNoEntries']."\n\t\t\t</div>\n";
    } else {
        //we have results, yeeeeeeeeey
        while($ROWnews = mysql_fetch_object($result)){
            //set link extensions by the news cat
            switch ($ROWnews->newsCat) {
                case 1:
                    $newsCat_link = "news";
                    break;
                case 2:
                    $newsCat_link = "statements";
                    break;
                case 3:
                    $newsCat_link = "events";
                    break;
            }
            //text summary
            if (strlen($ROWnews->newsShort) > 0 ) {$newsShortTxt = strip_tags($ROWnews->newsShort);
                if ($lang_id==2) { $newsShortTxt =  wbTranslit($newsShortTxt); }
            } else {
                $newsShortTxt = strip_tags($ROWnews->newsFull);
                if ($lang_id==2) { $newsShortTxt = wbTranslit($newsShortTxt); }
            }
            $newsShortTxt = wbShorTxt($newsShortTxt, 210, "... <a title=\"".$wb_lng['txtShowMore']."\" href=\"http://".$_SERVER['HTTP_HOST']."/".$lang_link."/".$newsCat_link."/".$ROWnews->newsId."/full/\">".$wb_lng['txtShowMore']."...</a>");
            //show news
            echo "\t\t<div class=\"sps_news_list\">\n";
            echo "\t\t<div class=\"sps_news_l\">\n";
            echo "\t\t\t<img alt=\"\" src=\"http://".$_SERVER['HTTP_HOST']."/content/images/news/_thumb/".$ROWnews->newsImageThumb."\" />\n";
            echo "\t\t</div>";
            echo "\t\t<div class=\"sps_news_r\">\n";
            //transliterate title
            if ($lang_id==2) { $newsTitle =  wbTranslit($ROWnews->newsTitle); } else { $newsTitle =  $ROWnews->newsTitle; } 
            echo "\t\t\t<div class=\"sps_news_title\">\n\t\t\t\t<a title=\"".$newsTitle."\" href=\"http://".$_SERVER['HTTP_HOST']."/".$lang_link."/".$newsCat_link."/".$ROWnews->newsId."/full/\">".$newsTitle."</a>\n\t\t\t</div>\n";
            echo "\t\t\t<div class=\"sps_news_date\">\n\t\t\t\t".$ROWnews->newsDate."\n\t\t\t</div>\n";
            echo "\t\t\t<div class=\"sps_news_text_sh\">\n\t\t\t\t".$newsShortTxt."\n\t\t\t</div>\n";
            echo "\t\t</div>";
            echo "\t\t</div>";
            //show <hr /> based on $count
            if($totalnews != $count) { echo "\t\t\t<hr />\n"; }
            $count++;
        }
    }
//pagination check
if($totalPages>$perPage) {
?>
                                <hr />
                                <div class="sps_pagginate">
                                   <?PHP wbPageTurnFront($PHP_SELF."/".$lang_link."/archive/", $totalPages, $page, $perPage); ?>
                                </div>
<?php 
    }
}
?>

Any ideas?
Tnx :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜还是长夜 2024-12-26 02:18:26

您是否可能正在寻找这样的东西?:

# start of page:
if (!isset($_SESSION['HasSearched']) {
    $_SESSION['HasSearched'] = 0;
}

// ...
// ...
// ...

# when you execute code for displaying search results
# check first if the session has been set:
if ($_SESSION['HasSearched'] == 0) {
    # proceed with search code
    # then set it to 1 since a search has been performed just now
    $_SESSION['HasSearched'] = 1;
} else {
    # this means a search had been previously made.
    # based on your requirement, no results should be displayed
    # since the assumption would be that a new search would be put in place

    # code to display fresh page with search form goes here

    # reset the session variable's value
    $_SESSION['HasSearched'] = 0;
}

如果没有,请告诉我们..

[编辑]基于帖子的新信息:

您可以尝试这个吗?:

<?php 
session_start();
# check if the form was submitted
if (isset($_POST['submit'])) {
    //get data from the form
    $archFld_1 = $_POST['archiveFld1'];
    $archFld_2 = $_POST['archiveFld2'];
    $archFld_3 = $_POST['archiveFld3'];
    //just some check on fields
    if (strlen($archFld_1) > 10) { $archFld_1 = ""; }
    if (strlen($archFld_2) > 10) { $archFld_2 = ""; }
    //save them as a array and store to session var
    $_archValues = array($archFld_3, $archFld_1, $archFld_2);
    $_SESSION['storeValues'] = $_archValues;
    $newSearch = 0;
} else if (isset($_GET['newSearch'])) {
    if ($_GET['newSearch'] == 1) {
        # new search requested by user (clicked link at the end (for now))
        $_SESSION['storeValues'] = NULL;
        $newSearch = 1;
    }
} else {
    # this may mean that the form was not submitted, nor was the `new search` link clicked
}

# let's check if we are just refreshing or taking from a new page or not
if (isset($_SESSION['storeValues'])) {
    //check params for search
    //set cat for query
    if ($_SESSION['storeValues'][0] > 0) { $valCat = "AND newsCat=".     $_SESSION['storeValues'][0] ." "; } else { $valCat = ""; }
    //set date for query
    if(($_SESSION['storeValues'][1] != "" ) && ($_SESSION['storeValues'][2] == "")) {
        $DateStart = $_SESSION['storeValues'][1];
        $valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') >= STR_TO_DATE('$DateStart', '%d-%m-%Y') ";
    }
    if(($_SESSION['storeValues'][2] != "") && ($_SESSION['storeValues'][1]=="")) {
        $DateEnd = $_SESSION['storeValues'][2];
        $valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') <= STR_TO_DATE('$DateEnd', '%d-%m-%Y') ";
    }
    if(($_SESSION['storeValues'][1]!="") && ($_SESSION['storeValues'][2] != "")) {
        $DateStart = $_SESSION['storeValues'][1];
        $DateEnd = $_SESSION['storeValues'][2];
        $valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') BETWEEN STR_TO_DATE('$DateStart', '%d-%m-%Y') AND STR_TO_DATE('$DateEnd', '%d-%m-%Y') ";
    }
    //query string and stire it to session
    $archQuery_string = $valCat.$valDate;
    $_SESSION['storeQuery'] = $archQuery_string;
} else {
    $_SESSION['storeQuery'] = '';
}

?>
    <div id="sps_middle">
        <div class="sps_cnt">
            <div id="sps_middle_ly1">
                <div class="sps_cnt_small">
                    <div class="sps_page_title"><h3><?php echo $wb_lng['txtArchiveTitle']; ?></h3></div>
                        <div class="sps_pages_cnt" style="padding-top: 10px; float: left; margin-bottom: 15px;">
                            <div class="sps_middle_col01">
                                <div style="float: left;">
                                <p>
                                    <?php echo $wb_lng['txtArchiveInfo']; ?>
                                </p>
                                    <form action="<?php $PHP_SELF; ?>" method="post" name="archiveForm" class="archiveForm">
                                        <ul>
                                            <li>
                                                <input name="archiveFld1" type="text" id="archiveFld1" value="<?php echo $wb_lng['txtArhivaFld_01']; ?>" />
                                                <input name="archiveFld2" type="text" id="archiveFld2" value="<?php echo $wb_lng['txtArhivaFld_02']; ?>" />
                                                <select name="archiveFld3">
                                                    <option value="0"><?php echo $wb_lng['txtArhivaFld_07']; ?></option>
                                                    <option value="0" ><?php echo $wb_lng['txtArhivaFld_06']; ?></option>
                                                    <option value="1"><?php echo $wb_lng['txtArhivaFld_03']; ?></option>
                                                    <option value="2"><?php echo $wb_lng['txtArhivaFld_04']; ?></option>
                                                    <option value="3"><?php echo $wb_lng['txtArhivaFld_05']; ?></option>
                                                </select>
                                            </li>
                                            <li style="float: right;">
                                                <input name="reset" type="reset" class="sps_archiveform_btn" value="<?php echo $wb_lng['txtArchiveFormReset']; ?>"/>
                                                <input name="submit" type="submit" class="sps_archiveform_btn" value="<?php echo $wb_lng['txtArchiveFormSend']; ?>"/>
                                            </li>
                                        </ul>
                                    </form>
                                </div>
                                <hr />
<?php

//pagination start 
$page = $_GET['id'];
$perPage = 10;
$result = wbQuery("SELECT * FROM wb_news WHERE newsLang=1 ". $_SESSION["storeQuery"] ."ORDER BY newsId DESC"); 
$totalPages = mysql_num_rows($result);
if (!$page) {
    $page = 1;
}
$start = ($page - 1)*$perPage;

if ($newSearch == 0) {
    //perform db query
    $result = wbQuery("SELECT * FROM wb_news WHERE newsLang=1 ". $_SESSION['storeQuery'] ."ORDER BY newsId DESC LIMIT $start, $perPage"); 
    //count rows
    $totalnews = mysql_num_rows($result);
    $count = 1;
    if($totalnews == 0) {
        //no results, say to the user
        echo "\t\t\t<div class=\"cil_news_text_big\">\n\t\t\t\t".$wb_lng['txtArchiveNoEntries']."\n\t\t\t</div>\n";
    } else {
        //we have results, yeeeeeeeeey
        while($ROWnews = mysql_fetch_object($result)){
            //set link extensions by the news cat
            switch ($ROWnews->newsCat) {
                case 1:
                    $newsCat_link = "news";
                    break;
                case 2:
                    $newsCat_link = "statements";
                    break;
                case 3:
                    $newsCat_link = "events";
                    break;
            }
            //text summary
            if (strlen($ROWnews->newsShort) > 0 ) {$newsShortTxt = strip_tags($ROWnews->newsShort);
                if ($lang_id==2) { $newsShortTxt =  wbTranslit($newsShortTxt); }
            } else {
                $newsShortTxt = strip_tags($ROWnews->newsFull);
                if ($lang_id==2) { $newsShortTxt = wbTranslit($newsShortTxt); }
            }
            $newsShortTxt = wbShorTxt($newsShortTxt, 210, "... <a title=\"".$wb_lng['txtShowMore']."\" href=\"http://".$_SERVER['HTTP_HOST']."/".$lang_link."/".$newsCat_link."/".$ROWnews->newsId."/full/\">".$wb_lng['txtShowMore']."...</a>");
            //show news
            echo "\t\t<div class=\"sps_news_list\">\n";
            echo "\t\t<div class=\"sps_news_l\">\n";
            echo "\t\t\t<img alt=\"\" src=\"http://".$_SERVER['HTTP_HOST']."/content/images/news/_thumb/".$ROWnews->newsImageThumb."\" />\n";
            echo "\t\t</div>";
            echo "\t\t<div class=\"sps_news_r\">\n";
            //transliterate title
            if ($lang_id==2) { $newsTitle =  wbTranslit($ROWnews->newsTitle); } else { $newsTitle =  $ROWnews->newsTitle; } 
            echo "\t\t\t<div class=\"sps_news_title\">\n\t\t\t\t<a title=\"".$newsTitle."\" href=\"http://".$_SERVER['HTTP_HOST']."/".$lang_link."/".$newsCat_link."/".$ROWnews->newsId."/full/\">".$newsTitle."</a>\n\t\t\t</div>\n";
            echo "\t\t\t<div class=\"sps_news_date\">\n\t\t\t\t".$ROWnews->newsDate."\n\t\t\t</div>\n";
            echo "\t\t\t<div class=\"sps_news_text_sh\">\n\t\t\t\t".$newsShortTxt."\n\t\t\t</div>\n";
            echo "\t\t</div>";
            echo "\t\t</div>";
            //show <hr /> based on $count
            if($totalnews != $count) { echo "\t\t\t<hr />\n"; }
            $count++;
        }
    }
    //pagination check
    if($totalPages>$perPage) {
?>
                                <hr />
                                <div class="sps_pagginate">
                                   <?PHP wbPageTurnFront($PHP_SELF."/".$lang_link."/archive/", $totalPages, $page, $perPage); ?>
                                </div>
<?php 
    }
}

# placing this code for your testing: i'm currently thinking that you'll need a user-ended trigger that a new search is desired
echo '<br /><a href=\'' . $_SERVER['PHP_SELF'].'?newSearch=1' . '\'> Perform a new search </a><br />';

?>

我想我可能有点困惑,但是给如果你不介意的话,这是一个镜头。

Is it possible that you might be looking for something like this?:

# start of page:
if (!isset($_SESSION['HasSearched']) {
    $_SESSION['HasSearched'] = 0;
}

// ...
// ...
// ...

# when you execute code for displaying search results
# check first if the session has been set:
if ($_SESSION['HasSearched'] == 0) {
    # proceed with search code
    # then set it to 1 since a search has been performed just now
    $_SESSION['HasSearched'] = 1;
} else {
    # this means a search had been previously made.
    # based on your requirement, no results should be displayed
    # since the assumption would be that a new search would be put in place

    # code to display fresh page with search form goes here

    # reset the session variable's value
    $_SESSION['HasSearched'] = 0;
}

If not, let us know..

[EDIT] Based on new information from post:

Could you try this?:

<?php 
session_start();
# check if the form was submitted
if (isset($_POST['submit'])) {
    //get data from the form
    $archFld_1 = $_POST['archiveFld1'];
    $archFld_2 = $_POST['archiveFld2'];
    $archFld_3 = $_POST['archiveFld3'];
    //just some check on fields
    if (strlen($archFld_1) > 10) { $archFld_1 = ""; }
    if (strlen($archFld_2) > 10) { $archFld_2 = ""; }
    //save them as a array and store to session var
    $_archValues = array($archFld_3, $archFld_1, $archFld_2);
    $_SESSION['storeValues'] = $_archValues;
    $newSearch = 0;
} else if (isset($_GET['newSearch'])) {
    if ($_GET['newSearch'] == 1) {
        # new search requested by user (clicked link at the end (for now))
        $_SESSION['storeValues'] = NULL;
        $newSearch = 1;
    }
} else {
    # this may mean that the form was not submitted, nor was the `new search` link clicked
}

# let's check if we are just refreshing or taking from a new page or not
if (isset($_SESSION['storeValues'])) {
    //check params for search
    //set cat for query
    if ($_SESSION['storeValues'][0] > 0) { $valCat = "AND newsCat=".     $_SESSION['storeValues'][0] ." "; } else { $valCat = ""; }
    //set date for query
    if(($_SESSION['storeValues'][1] != "" ) && ($_SESSION['storeValues'][2] == "")) {
        $DateStart = $_SESSION['storeValues'][1];
        $valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') >= STR_TO_DATE('$DateStart', '%d-%m-%Y') ";
    }
    if(($_SESSION['storeValues'][2] != "") && ($_SESSION['storeValues'][1]=="")) {
        $DateEnd = $_SESSION['storeValues'][2];
        $valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') <= STR_TO_DATE('$DateEnd', '%d-%m-%Y') ";
    }
    if(($_SESSION['storeValues'][1]!="") && ($_SESSION['storeValues'][2] != "")) {
        $DateStart = $_SESSION['storeValues'][1];
        $DateEnd = $_SESSION['storeValues'][2];
        $valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') BETWEEN STR_TO_DATE('$DateStart', '%d-%m-%Y') AND STR_TO_DATE('$DateEnd', '%d-%m-%Y') ";
    }
    //query string and stire it to session
    $archQuery_string = $valCat.$valDate;
    $_SESSION['storeQuery'] = $archQuery_string;
} else {
    $_SESSION['storeQuery'] = '';
}

?>
    <div id="sps_middle">
        <div class="sps_cnt">
            <div id="sps_middle_ly1">
                <div class="sps_cnt_small">
                    <div class="sps_page_title"><h3><?php echo $wb_lng['txtArchiveTitle']; ?></h3></div>
                        <div class="sps_pages_cnt" style="padding-top: 10px; float: left; margin-bottom: 15px;">
                            <div class="sps_middle_col01">
                                <div style="float: left;">
                                <p>
                                    <?php echo $wb_lng['txtArchiveInfo']; ?>
                                </p>
                                    <form action="<?php $PHP_SELF; ?>" method="post" name="archiveForm" class="archiveForm">
                                        <ul>
                                            <li>
                                                <input name="archiveFld1" type="text" id="archiveFld1" value="<?php echo $wb_lng['txtArhivaFld_01']; ?>" />
                                                <input name="archiveFld2" type="text" id="archiveFld2" value="<?php echo $wb_lng['txtArhivaFld_02']; ?>" />
                                                <select name="archiveFld3">
                                                    <option value="0"><?php echo $wb_lng['txtArhivaFld_07']; ?></option>
                                                    <option value="0" ><?php echo $wb_lng['txtArhivaFld_06']; ?></option>
                                                    <option value="1"><?php echo $wb_lng['txtArhivaFld_03']; ?></option>
                                                    <option value="2"><?php echo $wb_lng['txtArhivaFld_04']; ?></option>
                                                    <option value="3"><?php echo $wb_lng['txtArhivaFld_05']; ?></option>
                                                </select>
                                            </li>
                                            <li style="float: right;">
                                                <input name="reset" type="reset" class="sps_archiveform_btn" value="<?php echo $wb_lng['txtArchiveFormReset']; ?>"/>
                                                <input name="submit" type="submit" class="sps_archiveform_btn" value="<?php echo $wb_lng['txtArchiveFormSend']; ?>"/>
                                            </li>
                                        </ul>
                                    </form>
                                </div>
                                <hr />
<?php

//pagination start 
$page = $_GET['id'];
$perPage = 10;
$result = wbQuery("SELECT * FROM wb_news WHERE newsLang=1 ". $_SESSION["storeQuery"] ."ORDER BY newsId DESC"); 
$totalPages = mysql_num_rows($result);
if (!$page) {
    $page = 1;
}
$start = ($page - 1)*$perPage;

if ($newSearch == 0) {
    //perform db query
    $result = wbQuery("SELECT * FROM wb_news WHERE newsLang=1 ". $_SESSION['storeQuery'] ."ORDER BY newsId DESC LIMIT $start, $perPage"); 
    //count rows
    $totalnews = mysql_num_rows($result);
    $count = 1;
    if($totalnews == 0) {
        //no results, say to the user
        echo "\t\t\t<div class=\"cil_news_text_big\">\n\t\t\t\t".$wb_lng['txtArchiveNoEntries']."\n\t\t\t</div>\n";
    } else {
        //we have results, yeeeeeeeeey
        while($ROWnews = mysql_fetch_object($result)){
            //set link extensions by the news cat
            switch ($ROWnews->newsCat) {
                case 1:
                    $newsCat_link = "news";
                    break;
                case 2:
                    $newsCat_link = "statements";
                    break;
                case 3:
                    $newsCat_link = "events";
                    break;
            }
            //text summary
            if (strlen($ROWnews->newsShort) > 0 ) {$newsShortTxt = strip_tags($ROWnews->newsShort);
                if ($lang_id==2) { $newsShortTxt =  wbTranslit($newsShortTxt); }
            } else {
                $newsShortTxt = strip_tags($ROWnews->newsFull);
                if ($lang_id==2) { $newsShortTxt = wbTranslit($newsShortTxt); }
            }
            $newsShortTxt = wbShorTxt($newsShortTxt, 210, "... <a title=\"".$wb_lng['txtShowMore']."\" href=\"http://".$_SERVER['HTTP_HOST']."/".$lang_link."/".$newsCat_link."/".$ROWnews->newsId."/full/\">".$wb_lng['txtShowMore']."...</a>");
            //show news
            echo "\t\t<div class=\"sps_news_list\">\n";
            echo "\t\t<div class=\"sps_news_l\">\n";
            echo "\t\t\t<img alt=\"\" src=\"http://".$_SERVER['HTTP_HOST']."/content/images/news/_thumb/".$ROWnews->newsImageThumb."\" />\n";
            echo "\t\t</div>";
            echo "\t\t<div class=\"sps_news_r\">\n";
            //transliterate title
            if ($lang_id==2) { $newsTitle =  wbTranslit($ROWnews->newsTitle); } else { $newsTitle =  $ROWnews->newsTitle; } 
            echo "\t\t\t<div class=\"sps_news_title\">\n\t\t\t\t<a title=\"".$newsTitle."\" href=\"http://".$_SERVER['HTTP_HOST']."/".$lang_link."/".$newsCat_link."/".$ROWnews->newsId."/full/\">".$newsTitle."</a>\n\t\t\t</div>\n";
            echo "\t\t\t<div class=\"sps_news_date\">\n\t\t\t\t".$ROWnews->newsDate."\n\t\t\t</div>\n";
            echo "\t\t\t<div class=\"sps_news_text_sh\">\n\t\t\t\t".$newsShortTxt."\n\t\t\t</div>\n";
            echo "\t\t</div>";
            echo "\t\t</div>";
            //show <hr /> based on $count
            if($totalnews != $count) { echo "\t\t\t<hr />\n"; }
            $count++;
        }
    }
    //pagination check
    if($totalPages>$perPage) {
?>
                                <hr />
                                <div class="sps_pagginate">
                                   <?PHP wbPageTurnFront($PHP_SELF."/".$lang_link."/archive/", $totalPages, $page, $perPage); ?>
                                </div>
<?php 
    }
}

# placing this code for your testing: i'm currently thinking that you'll need a user-ended trigger that a new search is desired
echo '<br /><a href=\'' . $_SERVER['PHP_SELF'].'?newSearch=1' . '\'> Perform a new search </a><br />';

?>

I think I might be getting a bit confused, but give this a shot if you don't mind.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文