Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 带有get和选择器的搜索函数_Php_.htaccess_Search_Get - Fatal编程技术网

Php 带有get和选择器的搜索函数

Php 带有get和选择器的搜索函数,php,.htaccess,search,get,Php,.htaccess,Search,Get,如果标题不对,我很抱歉,但我不确定我到底想要什么(好吧,用英语怎么说) 基本上我有一个输入字段,在这里有人可以键入一些文本,然后按enter/按钮在数据库中搜索它。 该表单将他重新更正为site.com/search.php?search=my+dumb+text 但我希望有一个选择器(它将是下拉选择),这样他们可以按标题或用户进行查找,我希望搜索URL如下所示: site.com/search.php?user=dumb+name site.com/search.php?title=wird+

如果标题不对,我很抱歉,但我不确定我到底想要什么(好吧,用英语怎么说)

基本上我有一个输入字段,在这里有人可以键入一些文本,然后按enter/按钮在数据库中搜索它。 该表单将他重新更正为site.com/search.php?search=my+dumb+text 但我希望有一个选择器(它将是下拉选择),这样他们可以按标题或用户进行查找,我希望搜索URL如下所示:

site.com/search.php?user=dumb+name site.com/search.php?title=wird+title

澄清一下:我不希望URL是:site.com/rearch.php?user=dumb+name&type=user 否则我就不用问了

如果不使用JS或将表单作为POST发送,然后将其重新更正到search.php文件中,这是可能的吗

这就是现在的情况:

<div class='search'>
    <form method='get' action='search.php'>
    <select name='type'>
        <option value='title'>Title IMG</option>
        <option value='user'>User IMG</option>
    </select>
    <input type='text' name='search' value='$search' placeholder='Search' class='search-field'><input type='submit' value='s' class='search-button'>
    </form>
</div>

标题IMG
用户IMG

您想要的可能是一个收音机,让用户选择他想要的搜索类型:

<input type="radio" name="type" value="user">User<br>
<input type="radio" name="type" value="title">Title
用户
标题
这样,您将得到如下查询:search=A+B+C&type=user

这样比将“搜索”参数更改为其他参数更灵活

在没有js的情况下,无法动态更改提交表单的路径或表单中的字段名。


<div class='search'>
<?php echo "<form method='get' action='search.php?title= ".input_filter(INPUT_GET, 'search');." '>" ?>
<select name='type'>
    <option value='title'>Title IMG</option>
    <option value='user'>User IMG</option>
</select>
<input type='text' name='search' value='$search' placeholder='Search' class='search-field'><input type='submit' value='s' class='search-button'>
</form>
</div>

正如其他人指出的,我所希望的不是真的:没有重定向是不可能的,所以我使用.htaccess来完成它

以下是表格代码:

<div class='search'>
    <form method='get' action='search.php'>
        <select name='type' class='search-select'>
            <option value='replay' ".(isset($_GET['replay']) ? 'selected' : '').">Replays</option>
            <option value='player' ".(isset($_GET['player']) ? 'selected' : '').">Users</option>
        </select>
        <input type='text' name='search' value='$search' placeholder='Search' class='search-field'>
        <input type='submit' value='s' class='search-button'>
    </form>
</div>

PHP版本
你是说像
site.com/search.php这样的东西吗?user=dumb+name&title=weird+title
?旁注如果
value='$search'
来自php(假设是因为
'
到处都有引号),那么你对Jurik开放:这就是我不想要的。我希望URL是user=something或title=something,而不是两者都是。Loz:基本上我需要HTML方面的帮助,只是忽略PHP的内容,这与我的需求无关:)@MiChAeLoKGB我不完全理解你为什么要强迫URL变成那样,你能解释一下你为什么要这样做吗?也许你想研究一下重写规则?虽然在没有JS的情况下,你仍然很难让HTML表单按照你想要的方式工作。这主要是为了URL的外观。一切正常,我只是想让它看起来更好。这正是我不想要的。我忘了提了。然后,正如我在回答中提到的,没有js是不可能的,句号。好的,你刚刚确认了我所说的。我不想使用JS-tho,所以可能会发布并重新更正。或者两者兼而有之(js为主,post为备份)。我甚至不必尝试它就知道它不会工作。我希望标题部分是动态的,并且取决于用户在下拉菜单中选择的内容。所以会有标题或用户,而不总是只有一个。
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

RewriteCond %{QUERY_STRING} ^type=player&search=(.*)$ [NC]
RewriteRule ^search.php$ /search.php?player=%1 [L,R=301]
RewriteRule ^search.php?player=%1$ /search.php [L]

RewriteCond %{QUERY_STRING} ^type=replay&search=(.*)$ [NC]
RewriteRule ^search.php$ /search.php?replay=%1 [L,R=301]
RewriteRule ^search.php?replay=%1$ /search.php [L]
if (isset($_GET['type'])){
    if ($_GET['type'] == "player"){
        header("location:/search.php?player=".$_GET['search']);
        exit();
    }elseif($_GET['type'] == "replay"){
        header("location:/search.php?replay=".$_GET['search']);
        exit();
    }
}