0

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!

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.