in Education by
I am trying to paginate the results of an SQL query for use on a web page. The language and the database backend are PHP and SQLite. The code I'm using works something like this (page numbering starts at 0) http://example.com/table?page=0 page = request(page) per = 10 // results per page offset = page * per // take one extra record so we know if a next link is needed resultset = query(select columns from table where conditions limit offset, per + 1) if(page > 0) show a previous link if(count(resultset) > per) show a next link unset(resultset[per]) display results Are there more efficient ways to do pagination than this? One problem that I can see with my current method is that I must store all 10 (or however many) results in memory before I start displaying them. I do this because PDO does not guarantee that the row count will be available. Is it more efficient to issue a COUNT(*) query to learn how many rows exist, then stream the results to the browser? Is this one of those "it depends on the size of your table, and whether the count(*) query requires a full table scan in the database backend", "do some profiling yourself" kind of questions? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I've opted to go with the COUNT(*) two query method, because it allows me to create a link directly to the last page, which the other method does not allow. Performing the count first also allows me to stream the results, and so should work well with higher numbers of records with less memory. Consistency between pages is not an issue for me. Thank you for your help.

Related questions

0 votes
    As title really. I want to object just one specific value from a colum on one row of a SQL ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 3, 2022 in Education by JackTerrance
0 votes
    As title really. I want to object just one specific value from a colum on one row of a SQL ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    As title really. I want to object just one specific value from a colum on one row of a SQL ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    As title really. I want to object just one specific value from a colum on one row of a SQL ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I have a store to get a list of something in system. To get information by business requirement, this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    How can set row number for each table row created by dir-paginate angularJs. I use two way code ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I have a POST request that passes data to my database when the form is submitted. Photo of what I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I have a POST request that passes data to my database when the form is submitted. Photo of what I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    I am using autoencoders to do anomaly detection. So, I have finished training my model and now I want to ... y _true and y_pred Select the correct answer from above options...
asked Jan 29, 2022 in Education by JackTerrance
0 votes
    Which is the most efficient way to learn Splunk? Select the correct answer from above options...
asked Jan 6, 2022 in Education by JackTerrance
0 votes
    In what way is the closure compiler efficient? (a) Increases the size of the JavaScript files (b) ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    Which of the following is an efficient way to securely store passwords? (1)Abstraction (2)Hashing (3)Encryption...
asked May 17, 2021 in General by JackTerrance
0 votes
    A web page displays 10 items per page and has pagination enabled. What would be the recommended way to enable efficient ... (d)Hit the database every time user moves to next page...
asked Oct 6, 2020 in Technology by JackTerrance
0 votes
    I've always just FTPed files down from sites, edited them and put them back up when creating sites, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    i am developing an internal web analysis system like Google Analytics, i am not very clear about the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
...