【问题标题】:HTML url passing multiple parameters传递多个参数的 HTML url
【发布时间】:2018-10-10 13:48:11
【问题描述】:

我正在尝试使用 url 传递多个参数。我已经检查了几乎所有关于它的主题,但似乎找不到答案。我尝试了不同的方法,但仍然不起作用。

只发送第一个参数。

如果我以 post_id 开头 - 我无法获得 comment_id

如果我以 comment_id 开头 - 我不能得到 post_id

我对网址的看法:

http://localhost/index.php?post_id=3&comment_id=6

http://localhost/index.php?post_id=3&comment_id=6

我稍后尝试像这样使用它:

else if(isset($_GET['post_id']) & isset($_GET['comment_id'])){
        $post_id = $_GET['post_id'];
        $comment_id = $_GET['comment_id'];
        $user_id = $this->UserModel->getUser();
        $BlogPost = $this->BlogModel->getBlogPost($post_id);
        $BlogComments = $this->BlogModel->getBlogCommentList($post_id);
        $BlogComments = $this->BlogModel->deleteBlogComment($comment_id,$user_id);
        include 'views/ViewBlogPost.php';
}

【问题讨论】:

  • 您的第一个网址是正确的:http://localhost/index.php?post_id=3&comment_id=6。看起来您可能正在使用 PHP——我感觉接收查询的代码中有一些不正确的地方。另外,看看这个,我觉得这很有帮助:en.wikipedia.org/wiki/Query_string

标签: html url routing


【解决方案1】:

您的以下 URL 结构完全正确

http://localhost/index.php?post_id=3&comment_id=6

在脚本中通过 URL 传递数据的逻辑称为 QueryString,您可以按以下方式构建它 NAME=VALUE - 这称为名称值对,您可以通过仅附加“&”来传递多个名称值对 例如

 http://localhost/index.php?name_1=value_1&name_2=value_2

在服务器端,您将使用 GLOBAL $_GET 例如 print_r($_GET); 来检索它们查看所有传递的数据。

您可以单独使用 回声 $_GET['name_1'];回声 $_GET['name_2'];

另外我建议你检查你的 php.ini 中的 GPSC 设置来定义你的 Super Globals 之间的优先级。

【讨论】:

    猜你喜欢
    • 2021-09-12
    • 1970-01-01
    • 1970-01-01
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 2012-10-24
    相关资源
    最近更新 更多