Page 1 of 1

Deleting a query value from a URL

Posted: Wed Dec 15, 2004 5:38 am
by hairyjim
Is it possible to delete a query from a URL?

I tried unset($_get[submit]) but it did not do as I thought. I thought it would remove it from the URL string so all my links on the page that I generate dynamically would appear without &Submit=submit.

Is there some other function I need to look into that may help?

On a side not do people know of any good tutorials on using functions & classes? I feel comfortable with the basics of PHP and would now like to take the next steps in creating more efficient code.

Cheers
Jim

Posted: Wed Dec 15, 2004 5:45 am
by Weirdan
post your code. PHP itself does not generate &Submit=submit, it's you code where this parameter is added.

Posted: Wed Dec 15, 2004 5:46 am
by Bennettman
What I do, is to recreate the string using $_GET, with a simple validation on what's what.

Code: Select all

<?php

foreach ($_GET as $key => $value) {
     if ($key != 'submit') $get_string .= $key.'='.$value.'&';
}

?>

Posted: Wed Dec 15, 2004 6:41 am
by hairyjim
Weirdan wrote:post your code. PHP itself does not generate &Submit=submit, it's you code where this parameter is added.
Yeah I know that.

I have a form on my page that allows a user to filter the displayed results from a table.

There may be more than 1 page of results after filtering so I wish to be able to pass the filter parameters onto the next page.

I use PHP 5 function http_build_query($_GET) to grab the URL query so I can build it into my page links. I think Bennettman has given me the answer I was looking for.

Another question.

I have employed Bennettman's code to generate my URL query

Now my page links <a href tag looks like this:

Note I changed Bennettman's $get_string var to $geturl to fit in with what I was already working with.

Code: Select all

// Create page number links 
for ($i = 0; $i < $pages; $i++) &#123; 
$url = "pageid=" . $i; 
   if ($i == $pageid) 
   &#123; 
      echo "  <font class="CurrentPage">".($i + 1)."</font>  "; 
   &#125; else &#123; 
      echo "  <span class="Smallarticletext"><a href="test.php?". $geturl ."&". $url ."">".($i + 1)."</a></span>  "; 
         &#125; 
&#125;
So if I filter the page the a href looks like this:
test.php?&product=product1&pageid=1

So when I click on this all the correct parameters are passed on to the next page. But on this next page when i look at the a href it looks like this:
test.php?&product=product1&pageid=1&pageid=2

It appends the same pageid query onto the end of the url. All still works fine I presume because the latter pageid query is dominant.

What do I need to do to stop this though?

Posted: Wed Dec 15, 2004 10:52 am
by Bennettman
Just add a

&& $key != 'pageid'

to the if statement when making the $geturl. Stops the current $pageid from going in the URL as well as $result.

Posted: Wed Dec 15, 2004 10:58 am
by hairyjim
Cheers buddy. You have been a great help.

Jim