Ismail Altunören
Ismail Altunören

Reputation: 171

Send mail only once in while result php

I have this code

while($row = $rs->fetch_object()){
    echo $curl->get($row->site_url, 'sitekontrol', $row->id ).""; 
    if($row->site_url == "changed") {
        sendmail($mailadress);
    }
}

this sent to many times. i want to send just once on complate result.

This is sitecontrol system enter image description here

This is while enter image description here

Upvotes: 0

Views: 677

Answers (1)

Brian
Brian

Reputation: 1898

If you want to send the results once 10 sites change, you will have to keep track of this variable.

You may want to do something like this:

$changes = 0;

while($row = $rs->fetch_object() && $changes < 10){
    echo $curl->get($row->site_url, 'sitekontrol', $row->id ).""; 
    if($row->site_url == "changed") {
        $changes++;
    }
}

if($changes >= 10) {
    sendmail($mailadress);
}

EDIT: Changed to Federico klez Culloca's solution.

Upvotes: 1

Related Questions