Re: Page Numbering

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dan Shirah wrote:
Hello all,

I am having a problem with trying to display a set amount of records from my
result.
I have verified that the correct values for my variables are being passed to
the query.
The calculation for the records that should be displayed per page is
correct.
The total number of records returned from my query is correct.
And the calculated number of total pages to be displayed is correct.

So, initially it displays the first 10 results as it should, and has the
pages numbers at the bottom.  The problem is, when I click on a different
page number the same 10 results are ALWAYS displayed.  Even though my $page
variable IS being updated.

Any ideas why my results are not reflecting the page I select?


I would do it like this

This assumes that 'credit_card_id' is unique,

if it is not, then don't worry about reading the rest

<?php

# Get page number if passed to script
$page = intval( empty($_GET['page']) ? 1 : $_GET['page'] );

# Set number of rows to display from result set
$max_results = 10;

# Calculate the number of results that we have already looked at
$page_results = intval(($page*$max_results)-$max_results);

# Set your ORDER BY criteria.  This needs to be the same for each SQL statement
# This is why I have setup a variable, so no mistakes will be made
$order_by_criteria = 'credit_card_id';

# Figure out which SQL statement we need to use
if ( $page === 1 ) {

	# Query for page 1
$SQL = "SELECT	TOP {$max_results}
		Value1, Value2
	FROM	my_table
	ORDER BY {$order_by_criteria}";

} else {

	# Query for page 2 and greater
$SQL = "SELECT	TOP {$max_results}
		Value1, Value2
	FROM	my_table
	WHERE	credit_card_id NOT IN (
			SELECT	TOP {$page_results}
				credit_card_id
			FROM	my_table
			WHERE	my_table.column = 'P'
			ORDER BY {$order_by_criteria}
		) AS newtbl
	ORDER BY {$order_by_criteria}";

}

... run your $SQL statement here and work with the results
?>

--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux