选择“以10为一组的查询”

I followed one link here, and modified my code accordingly. What I am trying to do achieve is for example a table name media_ids contains 45 rows(which is dyanamic), I want to divide the no of rows in a group of 10 rows minimum (in my case four groups of 10 rows and 1 group of 5) and execute code of each group per hour.

For example from select record from id 1 to 10 then second hour from 11 to 20 and so on unless fetches the last record and start again from id 1.

I added a tracker, which check whats the current limit and proceed.But its giving me the required result what I am trying to achieve.

<?php
require('inc/dbConnect.php');

$lastPointerq = "select tracker from media_tracker";
$lastPointerResult = mysqli_query($con, $lastPointerq);
$lastPointerRes = mysqli_fetch_row($lastPointerResult);
$lastPointer = $lastPointerRes[0];
$lastPointer10=$lastPointer+10;

$currentMediaQuery = "select * from media_ids where id > ".$lastPointer." limit ".$lastPointer.",".$lastPointer10."";

$mediaQuery = mysqli_query($con, $currentMediaQuery);

if (mysqli_num_rows($mediaQuery) > 0) {
    while ($row = mysqli_fetch_assoc($mediaQuery)) {
       // do stuff…
      echo $id=$row['id']."<br>";
    }
}

else
{echo "0";}

if ($lastPointer + 10 > 40) {
    $lastPointer = 1;
} else {
    $lastPointer += 10;
}

mysqli_query($con, "update media_tracker set tracker = $lastPointer");
?>

I am assuming you are calling this script every hour via ajax/Js... In your code if you delete some data from another script you may find your first row id i.e 100 !

require('inc/dbConnect.php');

$limit = 10 ;
$lastPointerq = "select tracker from media_tracker";
$lastPointerResult = mysqli_query($con, $lastPointerq);
$lastPointerRes = mysqli_fetch_row($lastPointerResult);
$lastPointer = $lastPointerRes[0];

$lastPointerRes = mysqli_fetch_assoc($lastPointerResult);
$lastPointer = empty($lastPointerRes['tracker']) ?  0 : $lastPointerRes['tracker'] ;

$lastPointer10=$lastPointer* $limit;

$currentMediaQuery = "select * from media_ids  limit ".$limit." OFFSET  ".$lastPointer10."";

$mediaQuery = mysqli_query($con, $currentMediaQuery);

if (mysqli_num_rows($mediaQuery) > 0) {
    while ($row = mysqli_fetch_assoc($mediaQuery)) {
       // do stuff…
      echo $id=$row['id']."<br>";
    }
}

else
{echo "0";}

//do a total row count query here and set  as value of $total rather than 40
$total =40 ;
$flag = ceil($total/$limit);

if ($lastPointer == $flag) {
    $lastPointer = 0;
} else {
    $lastPointer ++;
}

mysqli_query($con, "update media_tracker set tracker = $lastPointer");