I'm having trouble with the function below. Basically what it is supposed to do is check IF each item from the array ($idDiscontinuedArray
) it's discontinued value from its respective table (either 1
or 0
).
Now I’m not sure to push these answers in an array to make the next part more simpler. At the moment the its spits $rows
out individually.
The result is: Array ( [discontinued] => 1, ) Array ( [discontinued] => 1 ) Array ( [discontinued] => 0 ) Array ( [discontinued] => 0 ) Array ( [discontinued] => 1 )....
where I would rather have Array [1] => 1 [2] => 1 [3] => 0 [4] => 0 [5] => 1....
The next part of the script is to check and see whether that ALL $rows = 1
which means end of script. If this is not the case this will run the function changeDiscontinued($dbh, $id, $idDiscontinuedArray)
.
function checkDiscontinued($dbh, $idDiscontinuedArray) {
try {
foreach ($idDiscontinuedArray as $id) {
$stmt = $dbh->query("SELECT discontinued FROM `$id` ORDER BY `date` DESC LIMIT 1");
$rows = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($rows);
}
if $rows['discontinued'] == TRUE) {
//echo $id . "Action if true";
} else {
changeDiscontinued($dbh, $id, $idDiscontinuedArray);
echo $id . "Items already discontinued!";
}
}
catch (PDOException $e) {
echo $e->getMessage();
}
}