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 ;)

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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