如何存储帖子变量值 [英] How to store post variables value
问题描述
我有一个包含搜索页面的索引页面,提交后,它通过操作和方法发布将值传递给find.php.代码在下面
I got a Index page on which search page is included, and when I submit it, it passes values to find.php through action and method post. The code is below
if($_POST['searchsubmit']=="Search"){
$cat=$_POST['searchcategory'];
$area=$_POST['searcharea'];
$term=$_POST['searchbox'];
}
上面的代码是写在find.php上的,现在,当我尝试通过基本分页方法实现分页时,要在何处进行适当的搜索查询条件
The above code is written on find.php, Now when I try to implement paging through basic paging method with where conditions to make appropiate search query
$where="where approved='yes'";
if($term!=""){
$where.=" and name like '%$term%'";
}
if($cat!=""){
$where.=" and category like '%$cat%'";
}
if($area!=""){
$where.=" and area like '%$area%'";
}
$start=0;
$end=5;
if($_GET['page']!="")
{
$start=$_GET['page']*$end;
}
其中$ start是我的初始限制,而$ end是我的记录数.对于分页的第一页,我将第一页的变量页面传递为0
Where $start is my initial limit, and $end is my number of records. For the first page of paging, I pass a variable page with 0 for first page
<a href="find.php?page=<?php echo 0;?>">First</a>
现在我的搜索查询变为
$que="select * from shops ".$where." ORDER BY likes DESC limit $start,$end";
当我单击第一个"时,我的新链接将变为"/find.php?page=0" 而且我从索引页搜索栏中获得的帖子值也丢失了.
As soon as I click on "first", My new link become "/find.php?page=0" and the post values which I recivied from index page search bar are lost.
有什么方法可以保留这些值吗?我还是通过GET通过url再次发送它们的两种方法,或者另一种方法是将它们存储在会话中. 有没有第三种方法?
Is there any way to retain those values ?The two methods which I though are sending them again through url with GET, or the other way is to store them in session. Is there any third method available ?
推荐答案
马克绝对正确.不要按原样使用代码.
Marc is absolutely right. Do not use the code as it is.
作为解决您问题的另一种方法-
As an alternate solution to your problem -
- 您的页面index.php(搜索表单)提交给自己
- 在搜索查询中将其作为poststring组合成index.php
- 使用组合的查询字符串重定向到find.php
- 所有搜索信息将始终位于查询字符串中.
- 愉快地使用分页.
这篇关于如何存储帖子变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!