1

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

4
  • What problem are you having? Your query string parameters should easily be accessible via $_GET['searchword'] and $_GET['page']. Commented Feb 27, 2012 at 16:47
  • @j08691 yes if you use & instead of multiple ? Commented Feb 27, 2012 at 16:51
  • @Lan Try use search before posting questions like that, these answer are easy to find -j08691 not via this syntax. Commented Feb 27, 2012 at 16:52
  • @NicolaPeluchetti - Ah good catch, I overlooked that. Commented Feb 27, 2012 at 16:55

6 Answers 6

3

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"
Sign up to request clarification or add additional context in comments.

Comments

2

You should use

mysite.php?searchword=vinegar&page=2

and in php

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

2 Comments

Or get it with $_REQUEST['page']` if You post the values
@silly Actually you should use $_POST['page'] if you post the values, but this is completely irrelevant as we're specifically talking about how to build the query string.
1

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

Comments

1

yes, use &

mysite.php?searchword=vinegar&page=2

Comments

1

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.

Comments

1

mysite.php?searchword=vinegar&page=2

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

Thats all you need.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.