为什么我的选择选项之一在表单提交时没有在查询字符串中放置任何内容?

发布于 2024-09-25 04:57:39 字数 690 浏览 0 评论 0原文

这是我的 HTML:

<select name="results"> 
    <option value="0">Vis alle</option> 
    <option value="10">10 resultater per side</option> 
    <option value="20">20 resultater per side</option> 
    <option value="30">30 resultater per side</option> 
    <option value="40">40 resultater per side</option> 
    <option value="50">50 resultater per side</option> 
    <option value="75">75 resultater per side</option> 
    <option value="100">100 resultater per side</option> 
</select>

当选择最上面的选项并提交表单时,获取变量“结果”将从 URL 中消失。我尝试用字符串“*”和“x”替换 0,但没有成功。

This is my HTML:

<select name="results"> 
    <option value="0">Vis alle</option> 
    <option value="10">10 resultater per side</option> 
    <option value="20">20 resultater per side</option> 
    <option value="30">30 resultater per side</option> 
    <option value="40">40 resultater per side</option> 
    <option value="50">50 resultater per side</option> 
    <option value="75">75 resultater per side</option> 
    <option value="100">100 resultater per side</option> 
</select>

When the topmost option is selected and form submitted, the get variable "results" disappears from the URL. I've tried switching out the 0 with strings "*" and "x" to no avail.

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

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

发布评论

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

评论(2

烟织青萝梦 2024-10-02 04:57:40

零值将被解释为“无”,因此从 $_GET 中消失。但对于你的情况来说这应该没有问题。您也可以只测试数组中的“结果”,以检查是否有人想查看所有结果。或者将零更改为字符串“all”并进行测试。

if (!isset($_GET['results']) {
    //logic for building your query without a LIMIT
}

A value of zero will get interpreted as "nothing" and therefore disappear from your $_GET. But that should be no problem in your case. You could also just test of the "results" is in the array to check if someone wants to see all. Or you change the zero to the string "all" and test for that.

if (!isset($_GET['results']) {
    //logic for building your query without a LIMIT
}
嘿咻 2024-10-02 04:57:40
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Your HTML5!</title>
    <?php
        if(isset($_GET['submit'])){
            echo $_GET['results'];
        }
    ?>
</head>
<body>
<form action="thisfile.php" method="GET">
<select name="results"> 
    <option value="0">Vis alle</option> 
    <option value="10">10 resultater per side</option> 
    <option value="20">20 resultater per side</option> 
    <option value="30">30 resultater per side</option> 
    <option value="40">40 resultater per side</option> 
    <option value="50">50 resultater per side</option> 
    <option value="75">75 resultater per side</option> 
    <option value="100">100 resultater per side</option> 
</select>
<input type="submit" value="submit" name="submit"/>
</form>


</body>
</html>

你正在这样尝试吗?如果是的话,那么它似乎适用于我的本地。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Your HTML5!</title>
    <?php
        if(isset($_GET['submit'])){
            echo $_GET['results'];
        }
    ?>
</head>
<body>
<form action="thisfile.php" method="GET">
<select name="results"> 
    <option value="0">Vis alle</option> 
    <option value="10">10 resultater per side</option> 
    <option value="20">20 resultater per side</option> 
    <option value="30">30 resultater per side</option> 
    <option value="40">40 resultater per side</option> 
    <option value="50">50 resultater per side</option> 
    <option value="75">75 resultater per side</option> 
    <option value="100">100 resultater per side</option> 
</select>
<input type="submit" value="submit" name="submit"/>
</form>


</body>
</html>

Are you trying like this? If yes then it seems to work on my local.

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