I m trying to do pagination on array in which i m collecting Data..!!!

as i can't use dynamic limit function at stored procedure...!! and without limit pagination cant be possible..!!
so i thought to collect data in a array and put pagination on it....!!!

hope anyone will help me..!!


Thanks..!

Recommended Answers

All 3 Replies

if you already have your data in an array then you can built it.

$start = $_GET['page']; // yourlink.php?page=0
$items = 5;
for ($i = $start * $items; $i < ($start * ($items + 1)); $i++) {
  // output your $array[$i]
}
Member Avatar for diafol

Hey, P, that's some mean code - beautiful.

You should be able to apply this code to the LIMIT clause in your sql string. The $items is equal to 'y', and the $start * $items is equal to 'x' (let's call it $start_at_this ), in the snippit below:

LIMIT x,y

For example, if you're showing 5 items per page and want to show page 0 (first one), then LIMIT 0,5 will show.

If you want page 1 as your first page, then you'll need to subtract one when creating the $start variable from the $_GET['page'] variable.

$query = "SELECT .... LIMIT {$start_at_this},{$items}";

innocent.boys,
Show us your code please. Wrap up source code with bb code tags.

[code=php] ... statements...

[/code]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.