I am making a search page based on $_GET. The page needs to be paginated, so values of $_GET['page'] will need to get updated as the user clicks the next/prev buttons. The problem is, everything is $_GET will dissappear if I do that. How can I go around this problem? Thanks.
$_GET contents
Moderator: General Moderators
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
$_GET contents
Hello,
I am making a search page based on $_GET. The page needs to be paginated, so values of $_GET['page'] will need to get updated as the user clicks the next/prev buttons. The problem is, everything is $_GET will dissappear if I do that. How can I go around this problem? Thanks.
I am making a search page based on $_GET. The page needs to be paginated, so values of $_GET['page'] will need to get updated as the user clicks the next/prev buttons. The problem is, everything is $_GET will dissappear if I do that. How can I go around this problem? Thanks.
- R4000
- Forum Contributor
- Posts: 168
- Joined: Wed Mar 08, 2006 12:50 pm
- Location: Cambridge, United Kingdom
Easy, use sessions.
Or if you really can't be bothered.
Use these two functions:
Basicly call them like:
In my system, this would echo: (if i had ?start_id=10)
But i do recommend sessions.
Or if you really can't be bothered.
Use these two functions:
Code: Select all
function create_next($link_to_next,$arguments){
echo "<form action=\"".$link_to_next."\" method=\"get\">";
foreach($arguments as $key=>$val){
echo "<input type=\"hidden\" name=\"".$key."\" value=\"".$val."\">";
}
foreach($_GET as $key=>$val){
echo "<input type=\"hidden\" name=\"".$key."\" value=\"".$val."\">";
}
echo "<input type=\"submit\" value=\"Next\">";
echo "</form>";
}
function create_prev($link_to_prev,$arguments){
echo "<form action=\"".$link_to_prev."\" method=\"get\">";
foreach($arguments as $key=>$val){
echo "<input type=\"hidden\" name=\"".$key."\" value=\"".$val."\">";
}
foreach($_GET as $key=>$val){
echo "<input type=\"hidden\" name=\"".$key."\" value=\"".$val."\">";
}
echo "<input type=\"submit\" value=\"Previous\">";
echo "</form>";
}Code: Select all
$next = array("test" => "lol");
create_next("search.php",$next);Code: Select all
<form action="search.php" method="get">
<input type="hidden" name="test" value="lol">
<input type="hidden" name="start_id" value="10">
<input type="submit" value="Next">
</form>But i do recommend sessions.
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
Sorry, been away from this project a few days. Anyway, inside the query string, there is a page number. I need to incriment that page number for my "next" button (pagination). Anyway, I'm trying to do it using preg_replace, but regex and I just don't play well together. Here's my code:
I then want to pass the new "querystring" to smarty to serve as the link. This is the warning PHP spits out:
Little help?
Thanks.
Code: Select all
$prev_page = preg_replace("\page=(0-9)","page=".$page-1, $_SERVER['QUERY_STRING']);Code: Select all
Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /home/public_html/search.php on line 115Thanks.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
It means exactly as it says, you didn't set your delimiter for the pattern correctly. I believe your pattern isn't the logic you want either.
PCRE calls require delimiters for the pattern, this delimiter is a symbol character, any, technically, but it is recommended to not use one that is used in patterns. Typical delimiters are /, #, and @.
PCRE calls require delimiters for the pattern, this delimiter is a symbol character, any, technically, but it is recommended to not use one that is used in patterns. Typical delimiters are /, #, and @.
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
hmm
Code: Select all
$str = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
$stripped = preg_replace("#page=\d{1,2}#i",$str);
echo $stripped;Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.