Code is designed to send a warning if no matches from the result set are found. However for some reason i found that my if statement if($send_warning = true)
is not executed at the right time.
According to the code it should execute once the while loop finishes and it should take $send_warning
variable to determine if the whole result set contained match or not and send warning accordingly.
Consider the following result set
1. 8.22.33.44
2. 9.88.44.33
3. 11.22.55.77
The $_SERVER["REMOTE_ADDR"]
evaluates to 11.22.55.77
So the loop starts obviously at the first index so it sets the $send_warning
to true on the first iteration - however the loop has not yet finished. At this point the the if statement is already triggered. Which is wrong - as it should wait until the whole loop finishes.
What am i missing here ??
$send_warning = false;
if ($result->num_rows > 0) {
// output data of each row
while($ip = $result->fetch_assoc()) {
var_dump($ip['ip_address']);
echo "<br>";
var_dump($_SERVER["REMOTE_ADDR"]);
if($ip['ip_address'] == $_SERVER["REMOTE_ADDR"]) {
$send_warning = false;
break;
var_dump("not sending");
} else {
var_dump("sending");
$send_warning = true;
}
}
if($send_warning = true) {
send($send);
}
} else {
//do nothing
}