Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
Filtering and sorting a Postgres table using both _POST and _GET via PHP

I have started working on a PHP based page which runs a SELECT query on a Postgres table and prints the result.

The page includes a form (POST method) which is being used to filter the table records, e.g. only show records which have values which lie within a particular min/max range for a particular field. The user is able to input values into the min/max fields of the form, and once they press the forms input button, the SELECT query is run again with an appropriate WHERE constraint. This part is working fine.

Now, I wanted to also include the ability for the user to sort the table according to each field. So, with some simple use of GET, I'm able to pass the parameters needed to sort the table via a href on each field header, e.g. "a href="index.php?field=x&order=asc..", which applies an appropriate ORDER BY constraint. This also works fine.

The problem is, when the user clicks one of the table headers in order to sort the table by that field, the page is obviously refreshed and any filters which were applied via the form are lost.

What's my best option to incorporate both of these features? That is, the user should be able to filter the table and then sort the the filtered records according to their desired field.

Do I need to re-think how I'm going about it completely?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can always use sessions to store the post.

Then just check if there is a post store it in the session and always filter by your session.

if($_SERVER['REQUEST_METHOD'] == 'POST'){
$_SESSION['filter'] = $_POST;
}
if(isset($_SESSION['filter'])){
//Run you query
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!