我已經寫了下面的代碼正確:Magento的選擇查詢不循環使用foreach循環
try {
$json = array('success' => true);
$read = $this->read;
$readresult = $read->fetchAll("SELECT * FROM brand");
foreach($readresult as $r) {
$json['brands'][] = array(
'id' => $r['brand_id'],
'name' => $r['name'],
'description' => $r['description'],
);
}
return $json;
} catch (Exception $e) {
$message = $e->getMessage();
echo json_encode(array("status" => "500", "error" => $message));
}
在這段代碼中,我試圖顯示從數據庫表中的所有品牌的記錄。
但問題是,當我試圖輸出結果,它只顯示一條記錄。
任何人都可以請檢查是什麼問題。
代碼的輸出上面是:
{
"success":true,
"products":[
{
"id":"4",
"name":"Test",
"href":"http:\/\/localhost:81\/magento\/index.php\/catalog\/product\/view\/id\/4\/",
"thumb":"http:\/\/localhost:81\/magento\/media\/catalog\/product\/cache\/0\/thumbnail\/9df78eab33525d08d6e5fb8d27136e95\/images\/catalog\/product\/placeholder\/thumbnail.jpg",
"pirce":"$111,111.00"
}
]}
傢伙請人幫助沒有人在那裏? –
如果您還需要其他東西,您也可以告訴我 –