php - 如何通过更改 url 参数并在 php 中按 Enter 键来搜索结果

标签 php mysql

我想通过更改参数值并按地址中的回车键来搜索结果。 当我在主页上搜索时,我使用这种形式在网址中传递搜索关键字

eg:->http://localhost/mydeals/searchListing.php?sRes=g

现在,当我在 searchListing.php 上时,我想将 sRes 的参数更改为 p ,之后当我在地址栏中按 Enter 键时,我会得到 $_GET 中的值,那么我如何搜索它。

eg:->http://localhost/mydeals/searchListing.php?sRes=p

我在配置文件中编写的 php 代码是。

if(isset($_POST['search2']))
    {
        if(trim($_POST['location2'])!="" && $_GET['sRes'] =="")
        {
            $_SESSION['dirLocation2'] = trim($_POST['location2']);
            header("location:".THIS_DOMAIN."searchListing.php?sRes=".$_SESSION['dirLocation2']);
        }else if($_GET['sRes'] !=""){
            $_SESSION['dirLocation2'] = trim($_GET['sRes']);
            header("location:".THIS_DOMAIN."searchListing.php?sRes=".$_SESSION['dirLocation2']);
        }else{
            header("location:".THIS_DOMAIN."index.php");    
         }
    }

    if (empty($_GET["sRes"])) {
        header("location:".THIS_DOMAIN."index.php");    
    } else{
        $_SESSION['dirLocation2'] = trim($_GET['sRes']);
            header("location:".THIS_DOMAIN."searchListing.php?sRes=".$_SESSION['dirLocation2']);
    }

最佳答案

您可以通过检查 url 参数来做到这一点,例如;

<?php

if (empty($_GET["sRes"])) {
    header("Location: index.php");
} else {
    $sResValue = $_GET["sRes"]; // p, or s
    // Do your search here
}

关于php - 如何通过更改 url 参数并在 php 中按 Enter 键来搜索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23670366/

相关文章:

javascript - 将附件上传到 Wordpress 中的页面

php - CRUD Laravel 4如何链接销毁?

php - 有没有办法使用 PHP 检查文件是否已完全上传?

php - AddClass ('selected' ) 在共享标题的菜单上

mysql - 如何使 Rails 3.1 在 Debian squeeze 上与 MySQL Server 5.1 一起工作?

php - 连接到服务器时为 "parse error, expecting , or ;"

php - Laravel 查询 : BadMethodCallException in Builder. php 行 2258:

php - MySQL 查询来选择特定的 DATETIME 值?

mysql - 使用两个表过滤表的 SQL 查询

php - 如何为 php 中网站表单的实际序列创建序列号