HTML URL传递多个参数

时间:2018-10-10 13:48:12

标签: html url routing

我正在尝试通过url传递多个参数。我已经检查了几乎所有有关此主题的内容,但似乎找不到答案。我尝试了不同的方法,但仍然无法正常工作。

它只发送第一个参数。

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

如果我以comment_id开头-我将获得post_id

我对网址的想法:

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

OR

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';
}

1 个答案:

答案 0 :(得分:0)

您下面的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设置,以定义超级全局变量之间的优先级。