0
查找以下代碼以從此查詢創建1和0的數組。目前,從$行的結果是:來自SQL查詢的foreach循環的數組結果
Array ([discontinued] => 1,) Array ([discontinued] => 1) Array ([discontinued] => 0) Array ([discontinued] => 0) Array ([discontinued] => 1)....
,我寧願有這樣的事情:
Array [1] => 1 [2] => 1 [3] => 0 [4] => 0 [5] => 1....
任何人都可以幫助我在這一點,將不勝感激。 請不要評論代碼中的漏洞;我知道它已經在那裏。我只是一個初學者...我只想要它的核心膽量工作。
乾杯! :)
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();
}
}
無論如何,我可以修改我的代碼以獲得像Array [1] => 1 [2] => 1 [3] => 0 [4] => 0 [5] => 1 – DrDog