Reputation: 908
So my problem is the following:
I am developing a WordPress plugin, and i am getting values from a custom database table. Lets call the table devices. From the device table, i am now getting all entries from the colum ids. But there is my problem: If this colum has more then 1000 entries, i need the "split" them, i mean, i need first to get the first 1000 entries, then the next 1000 until i reach the end. Any ideas how to do this in php?
For example, this is how i get the ids now:
function hlp_getIds() {
global $wpdb;
$table_name = $wpdb->prefix.'devices';
$devices = array();
$sql = "SELECT id FROM $table_name";
$res = $wpdb->get_results($sql);
if ($res != false) {
foreach($res as $row){
array_push($devices, $row->id);
}
}
return $devices;
}
So how can i integrate a method to get only each 1000 entries and not all the entries at once?
Upvotes: 0
Views: 684
Reputation: 204756
Use limit
select id
from device
order by id
limit 0, 1000
to get the next 1000 do
select id
from device
order by id
limit 1000, 1000
Upvotes: 4