// ?page=1 ?page=2 ?page=3 ... ?page=n $page = $HTTP_GET_VARS['showpage'] // max record per page $max_results_per_page = 10; $sql = "SELECT * FROM `records`"; if ( !($retid = $db->sql_query($sql) ) die ( "Error: "); while ( $row = $db->sql_fetchrows($retid) ) { printf ("%s<br>", $row[name] ); }
the goal is to display specified records on a current page request
please help. thanks in advance! 🙂
Ok - If your showpage is just going up by one each time add
$offset=$max_results_per_page * $page;
$sql="SELECT * FROM records LIMIT $offset, $max_results_per_page";
That's if you're using MySQL with that database class.
thanks for a reply. but it seems that there is a problem with my script. it doesn't display any records unless i jumped on the next page. The script returns 2 records only 🙁
$max_result = 3; if ( $page < 1 ) $page = 1; $offset = $max_result * $page; $sql = "SELECT * FROM `$prefix" . "data` LIMIT " . $offset . ", " . $page; $db->buffered_db_query($sql);
the returned value of $sql is
SELECT * FROM _gb_1_data LIMIT 3, 1
_gb_1_data
$sql = "SELECT * FROM `$prefix" . "data` LIMIT " . $offset . ", " . $max_results_per_page;
notice the difference
it should be $max_results_per_page not $page , in there