Reputation: 197
I am loading data from mysql database using php. But i want to limit loading to specific number of row (for example: 10 rows) and also add load more feature to get more rows using Jquery ajax.
Thank you in advance!
Upvotes: 0
Views: 667
Reputation: 602
To limit your query in MySQL: (this will return the first 10 rows)
select * from table_name limit 10
Then in javascript you'd probably need to keep count of how many times you have queried the db so you're queries would be similar to:
select * from table_name limit 10,20
// 20,30 40,50 etc etc etc
// for example say you pass in a count variable, so this would be
// 3rd time you've queried
// $_POST = 3
$lower = ($_POST['count'] * 10) - 10;
$upper = $_POST['count'] * 10;
// would result in:
select * from table_name limit $lower, $upper // 20, 30
However you could also use mysql's offset
keyword
$offset = $_POST['count'] * 10;
select * from table_name limit 10 offset $offset
Which is basically getting the next 10 rows from the db every you query from AJAX.
Upvotes: 2