Arrary Count Inside While Loop

I run a select query the returns 10,000-100,000 unique items
then a while loop that performs ten or so functions.

what i need to do is group the results by 10 and then run a function on those 10 at one time then update the same table with the results of the function. i know how to run the while loop and write the functions but i cant get around the group by ten run the function and then move on to next until the while loop is complete.

$results = $conn->query("select asin from masterguide25ManFinal ");
while ($rows = $results->fetch_assoc()) {
$asin = $rows['asin'];

Store your data in a “batch” that is handled once it reaches your chosen side, then reset.

$results = $conn->query("select asin from masterguide25ManFinal ");
$this_batch = array();
while ($rows = $results->fetch_assoc()) {
    $this_batch[] = $rows['asin'];
    // Once you have a batch, run the update then reset the batch
    if (count($this_batch) == 10) {
        store($this_batch);
        $this_batch = array();
    }
}

/**
 * If your number of rows is not divisible by ten
 * there may be a partial batch left to process once the loop has completed
 */
if (!empty($this_batch)) {
        store($this_batch);
}

What exactly are you doing? What are these 10 functions? If you are just updating the DB data you shouldn’t even need Php.

there are a dozen different functions i am running before i update the database again-what skawid posted got me unstuck–i am working on it now i will post when i have complete answer

skawid this worked perfectly --cut my time down by 1/5th

Sponsor our Newsletter | Privacy Policy | Terms of Service