Reputation: 35
I've been trying to work this one out in my head for hours and still no luck so I'm resulted to here.
For some reason when the code has the query uncommented the loop will only loop once even tho there are 3 logs in the database if we then comment the query it works as expected.
$sth = $dbh->prepare("SELECT * FROM `savedusers`");
$sth->execute();
while($row = $sth->fetch(PDO::FETCH_ASSOC)){
$run++;
foreach($sites as $site){
$clients = ${CalculateControllerVar($site['site_id'])}->list_clients($site['site_id']);
foreach($clients as $client){
if(strtolower($client->mac) == strtolower($row['Mac'])){
$aps = ${CalculateControllerVar($site['site_id'])}->list_aps($site['site_id'], $client->ap_mac);
$sth = $dbh->prepare("UPDATE `savedusers` SET `Location` = :loc WHERE `Mac` = :mac");
$sth->execute(array(':loc' => $aps[0]->name, ':mac' => $row['Mac']));
}
}
}
}
Thanks in advance.
Upvotes: 1
Views: 40
Reputation: 4021
It is because you are overwriting variable $sth
in your commented code. Change those lines to:
$sth2 = $dbh->prepare("UPDATE `savedusers` SET `Location` = :loc WHERE `Mac` = :mac");
$sth2->execute(array(':loc' => $aps[0]->name, ':mac' => $row['Mac']));
and it will work properly.
Upvotes: 2