1
http://example.com/bills.php?sort=highest 
http://example.com/bills.php?sort=alpha
http://example.com/bills.php?sort=lowest

So the urls aboves sort by highest, alphabetical and lowest. They use the $_GET method with the use of a form. I was wondering if there was a way to submit the form/get the $_GET data without changing the url?

<form action="bills.php" method="get">
    <select onchange="this.form.submit();" name="sort" class="right sort">
        <option>What would you like to sort by?</option>
        <option value="highest" <?php if(isset($_GET['sort']) && $_GET['sort'] == 'highest'){?> selected="selected" <?php } ?>>Highest to Lowest</option>
        <option value="lowest" <?php if(isset($_GET['sort'])&& $_GET['sort'] == 'lowest'){?> selected="selected" <?php } ?>>Lowest to Highest</option>
        <option value="alpha" <?php if(isset($_GET['sort'])&& $_GET['sort'] == 'alpha'){?> selected="selected" <?php } ?>>Alphabetically</option>
    </select> 
</form>

Above is the code in which I am able to submit a new sort request.

I would like to make my url stay at example.com/bills.php would that be possible?

Would this be possible rewriting the url using .htaccess? I have tried a URL rewriting method which allows me to visit http://example.com/bills/alpha and it works fine, but when I select a new query, it turns into http://example.com/bills/bills/?sort=alpha.

Here's my .htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^bills/(.*)$ /bills.php?id=$1
3
  • 2
    Use form method as post and keep the values in a hidden field under the same form Commented Jun 26, 2013 at 9:39
  • Is there any reason you're not using post? Commented Jun 26, 2013 at 9:41
  • I wanted to have the ability to be able to make a query with the use of variables also by typing it in. I was just wondering if there was any way to to use $_GET and have the url revert to bills.php after the query was done. If not I would like to find out how I could take an alternative and use URL rewriting. Commented Jun 26, 2013 at 9:44

1 Answer 1

5

Using AJAX, you can solve this problem. No need to do any changes in .htaccess. Here is the code which can helps you :

 $(".right").change(function(){
    $.get("YourFile.php",{"sort":$(this).val()},function(res){
       alert(res);
   });
}); 
Sign up to request clarification or add additional context in comments.

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.