RE: Search engine won't page properly

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

 



Bill,

That's a lot of reading ... Anyway, this seems to be a 'general' PHP
question.  If I understood you correctly, you're having problem getting PHP
to page the SQL results?  If so, look the below code logic and adapt as
necessary:

$numOfResults = 10; // change this to your need
if( !empty($_GET['page']) && intval($_GET['page']) > 1 ) $currentPage =
intval($_GET['page']) - 1; // change the $_GET['page'] accordingly
elseif (!empty($_GET['page']) && strtolower(trim($_GET['page'])) == 'all')
$currentPage = 'all';
else $currentPage = 0;

$sqlQuery = 'SELECT * FROM my_table ';

If( $currentPage != 'all' ) $sqlQuery .= ' LIMIT
'.$currentPage*$numOfResults.', '.$numOfResults; // see [1]

$result = mysql_query($sqlQuery);

Would give you the following:

?page=all returns all results
?page=1 or ?page=0 or ?page= or ?  yields 1st batch $numOfResults ( 1 to 10
)
?page=2 yields 2nd batch $numOfResults ( 11 to 20 )
?page=3 yields 3rd batch $numOfResults ( 21 to 30 )
?page=4 yields 4th batch $numOfResults ( 31 to 40 )

Etc....  

Regards,
Tommy

[1] http://dev.mysql.com/doc/refman/5.1/en/select.html


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



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux