pagination in simpledb

别来无恙 提交于 2019-12-22 00:23:17

问题


i have tried offset in simpledb but its not working as it working in mysql , and i want to do paging for my database api in php so that i send the pagenumber and pagelength to the query and it will return the data of that page only. How this i can do in simpledb.

    select * from second 
where time_stamp is not null and gibid = '54' and gibview = 'O' 
order by time_stamp asc limit $pagelength 

as offset is not working so i can't add offset in query. I have google and find there is next token is returned but i am not getting nexttoken. how to check for nexttoken.

Please help .

Thanks


回答1:


Per the Simpledb team (this question was asked in their forums) using the next token is the way to do it.

If you want to grab, say the 2500-2600th item from a list and not iterate over the first 2500, the simpledb team recommends doing a count(*) up to 2500, cause it is fast, then grabbing the next token from that result and then issuing your real query to pull the names and attributes.

Clever hack to the fact that limit doesn't take a starting index I thought, but should save you some performance. Just wanted to share that.




回答2:


$pagelenght should be :

$pagenum = 4; //current page
$numitems = 20; //items per page
$row_from = $pagenum * $numitems - $numitems;
$pagelenght = $row_from.','.$numitems; 


in the end pagelenght should look like this
$pagelenght = '0,20'; //first page
$pagelenght = '20,20'; //second page
$pagelenght = '40,20'; //third page
$pagelenght = 60,20'; //forth page

something like this, first number is from which row, and second is number how many items in one page.




回答3:


Done By Using NextToken in simple db

$files = $this->db->select($domain, $query, $offset)

Here $offset is nexttoken string which will pass in query. and will return next page.




回答4:


I confirm that LIMIT in SimpleDB only takes one argument.

To be sure, I tried the following query (the domain Person exists): "SELECT * FROM Person LIMIT 20, 20" and I had the following response: Client error : The specified query expression syntax is not valid.

Even if limit is not specified, SimpleDB applies a default limit 100, the maximum limit is 2500 rows. I want to stress out that LIMIT works differently from other databases. LIMIT 100 means that you'll get 100 results per time, and you'll get another batch of 100 results with the next token (provided that there is enough data of course).

The way to do the pagination is use tokens. Already obtained token can be stored in the session, so it will be possible to go back to previous pages.



来源:https://stackoverflow.com/questions/4623324/pagination-in-simpledb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!