Amit Kaushal
Amit Kaushal

Reputation: 439

fetch next n records from table php mysql

I am currently showing latest top 5 records from table and on click of button want to show next 5 records from table. How can I do this in mysql.

Upvotes: 0

Views: 693

Answers (3)

raju gupta
raju gupta

Reputation: 59

We can used

SELECT * FROM yourtablename LIMIT nth,5

Upvotes: 0

Sagar
Sagar

Reputation: 647

var page=1;
// On user button click, increment 'page' variable
$( "#button" ).click(function() {
page++;
//call php function getRecords();
});

function getRecords($page){

$start = 5*$page;
$limit = 5;

// fetch data by following query

SELECT *
FROM `table`
LIMIT $start,$limit

} 
}

Above code is flow of logic. There might be some syntax errors.

Upvotes: 1

Jay Blanchard
Jay Blanchard

Reputation: 34416

From the docs -

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants (except when using prepared statements).

SELECT *
FROM `table`
LIMIT 5,5

Upvotes: 1

Related Questions