When I run this query and $from has a really big value, it takes too much in returning the answer (more than 30 secs).
Is there any way to go directly to the $from row and return $users_per_page amount of records without go through the whole database?
$query = 'SELECT * FROM users ORDER BY user_id LIMIT ' . $from. ' , '. $users_per_page;
Adding an index on user_id will prevent a table scan. As long as users_per_page is small then the query will be fast.
CREATE INDEX index_users_on_user_id ON users (user_id);