Problem with random results and pagination

Discussion in 'PHP' started by seofighter, Jul 16, 2010.

  1. #1
    Hi,,

    I have a search engine pulling the results from a MYSQL database with pagination.

    THE PROBLEM: I need the results to come up random on all the pages after each search or whenever the page is refreshed without doubling. I can do it with one page but the problem is with more pages.

    I'll be very grateful if somebody can come up with any ideas as I cannot find a solution anywhere.
     
    seofighter, Jul 16, 2010 IP
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    It shouldn't be hard if you think of it logically, what you have to understand are the parameters of LIMIT - first param is the offset, second param is the rows per page.

    Here's a little calculation of offset that I just thought up:
    
       function calculateOffset($pageNum, $rowsPerPage) {
          $tempOffset = $pageNum * $rowsPerPage;
          return ($tempOffset > $rowsPerPage) ? ceil($tempOffset-$rowsPerPage) : 0;
       }
    
    PHP:
    $pageNum is the current page number, which is usually page 1. This changes when you go to page 2 and so on.
     
    Rainulf, Jul 17, 2010 IP