Long before humans walked the Earth, dinosaur network engineers noticed that networks could be slow sometimes. Sending thousands and tens of thousands of lines across a network could be a serious performance problem. A particularly clever Tyrannosaur used its stubby arms to type out the first paging algorithm.

This ancient technology is well understood. So this particular bug report perplexed Kamen:

User can only retrieve the first 75 entries in the system. They only ever see three pages, with 25 items per page. The user reports that there are over 1,000 records in the system.

It didn’t take Kamen long to find the problem:

$page = (int)$_GET['page'];
if($page == 1){$limit = 0;$this_page = 1;$prev = 1;$next = 2;}
elseif($page == 2){$limit = 25;$this_page = 2;$prev = 1;$next = 3;}
elseif($page == 3){$limit = 50;$this_page = 3;$prev = 2;$next = 3;}
else{$limit = 0;$this_page = 1;$prev = 1;$next = 2;}
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!