Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda