Jump to content

Default/Rollback Values in PHP $_GET instances


dragon2309

Recommended Posts

Hi all, wonder if you can help me. To cut a long story short, I am attempting to paginate my mysql results by using the "limit" clause in an SQL query, but i want the number of results per page to be able to be set by the user. The way I want to go about this may mean that at times the user hasnt selected anything, so I need a way to be able to embed a default value in a PHP $_GET function if there has been no user input, and of course for this value to be ignored if the user has expressed they want it to be different than the default (say 10 records per page)

 

Any ideas, I'm fairly open to changing my tactics, as long as it makes sense in my head I can usually work at it, so bring your ideas.

 

Cheers in advance, Dave ;)

Just before you start pulling your data, do a test:

 

 

<?php
  $limit = 10;
  if(is_numeric($_GET['limit']) && $_GET['limit'] > 0){
    $limit = $_GET['limit'];
  }

  //Now pull your records using the value of $limit

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.