我試圖從fetchAll從MySQL獲取某些數據。選擇數組中的數據與PDO fetchAll
目前,我有這樣的:
$sql1= $dbh->query("SELECT * FROM information");
$comments= $dbh->prepare("SELECT * FROM comments WHERE idinformation= ?");
if($retail){
while($row = $retail -> fetch(PDO::FETCH_ASSOC)){
$comments->execute(array($row['idproducts']));
$json['data'][] = array(
'id'=>$row['idproducts'],
"headline"=>$row['headline'],
'price'=> array ("full_price" => $row['full_price']),
'description'=>$row['description'],
"comments" => $comments->fetchAll(PDO::FETCH_ASSOC)
);
}
$json_encode = json_encode($json);
$obj = json_decode($json_encode,true);
}
我的意見是輸出所有列在我的數據庫。如果我只想要評論,時間,ID等等,我該怎麼區分這個語法?
在此先感謝!
而不是「*」在查詢中寫入列名。 – itachi