Jump to content

remove old value from query


wkilc

Recommended Posts

I'm a noob, tring to reverse engineer some current code.

 

This code is grabbing the current URL:

 

<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>

 

This form is adding "&limit=50" to the URL, to show 25, 50 or 100 results per page:

<form>
<select name="link">
<option <? echo "$select25" ?> value="<? echo curPageURL(); ?>&limit=25">25 records per page</option>
<option <? echo "$select50" ?> value="<? echo curPageURL(); ?>&limit=50">50 records per page</option>
<option <? echo "$select100" ?> value="<? echo curPageURL(); ?>&limit=100">100 records per page</option>
</select>
</form>

 

The problem is here (I think).  This is supposed to flush the old limit before requesting a new one... but right now, I'm getting another one tacked on with each new request:

www.website.com/members?sub[]=math&sub[]=science&lev[]=middleschool&limit=25

www.website.com/members?sub[]=math&sub[]=science&lev[]=middleschool&limit=25&limit=50

www.website.com/members?sub[]=math&sub[]=science&lev[]=middleschool&limit=25&limit=50&limit=100

<?php 
//remove any old limit from query
$tmp = array();
foreach ($_GET as $fld => $val)
    if ($fld != 'limit')
         $tmp[] = $fld . '=' . $val;
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"] . '?' . implode('&',$tmp);
?>

 

Any ideas?

 

Thanks.

 

~Wayne

 

 

 

Link to comment
Share on other sites

There's also the stristr function which you can locate the first occurence of "&limit=" and pull everything before that using one function and putting true as the third param.  Here's an example from php.net (http://www.php.net/manual/en/function.stristr.php)

 

<?php

  $email = 'USER@EXAMPLE.com';

  echo stristr($email, 'e'); // outputs ER@EXAMPLE.com

  echo stristr($email, 'e', true); // As of PHP 5.3.0, outputs US

?>

 

 

Link to comment
Share on other sites

Thank you.

 

Again, I'm pretty green...

 

<?php
  $curPageURL = $curPageURL;
  echo stristr($curPageURL, '&limit='); // outputs ER@EXAMPLE.com
  echo stristr($curPageURL, '&limit=', true); // As of PHP 5.3.0, outputs US
?>

 

gives me:

 

Warning: Wrong parameter count for stristr()

 

Thanks.

 

~Wayne

Link to comment
Share on other sites

Just realized that there might be variables after &limit= that I would want to keep...

 

So I'm back to:

 

//remove any old limit from query
$tmp = array();
foreach ($_GET as $fld => $val)
    if ($fld != 'limit')
         $tmp[] = $fld . '=' . $val;
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"] . '?' . implode('&',$tmp);

 

Just trying to flush the current "limit"... this has worked in other instances for me before.

 

~Wayne

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.