【发布时间】:2012-06-23 06:43:54
【问题描述】:
我正在尝试使用 fetchAll 从 mysql 获取某些数据。
我目前有这个:
$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);
}
我的 cmets 输出了我数据库中的所有列。如果我只想要 cmets、time、id 等怎么办……在这种语法中我该如何区分呢?
提前致谢!
【问题讨论】:
-
在查询中写入列名而不是“*”。