简体   繁体   中英

Double PHP URL query GET

Basically my question is:

mysite.php?searchword=vinegar?page=2

In the above url is it possible to GET both the search value (which here is vinegar) and the page value (here 2) with PHP code?

It comes from searching a large mysql table for the word vinegar, and then paginating the results. If this is not how possible, please could you suggest a way to do this

Thanks

You should use

mysite.php?searchword=vinegar&page=2

and in php

$search = $_GET['searchword'];
$page = $_GET['page'];

The question mark in a URL denotes the beginning of the query string . Your URL may contain only one query string. Within the query string, multiple key=value pairs are separated by an ampersand, &:

mysite.php?searchword=vinegar&page=2

PHP makes the contents of your query string available via the super-global associative array $_GET :

$_GET['searchword']; # "vinegar"
$_GET['page']; # "2"

No because the syntax is wrong. URL parameters should be in the format:

mysite.php?searchword=vinegar&page=2

And then you use $_GET['chword'] and $_GET['page'] to retrieve them in PHP

是的,使用&

mysite.php?searchword=vinegar&page=2

There should only be 1 question mark after the .php . The URL should be written like this: mysite.php?searchword=vinegar&page=2 , then PHP will get both the searchword and page value.

mysite.php?searchword=vinegar&page=2

$word = $_GET["searchword"]
$page = $_GET["page"]

Thats all you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM