由於某種原因,我返回的數組不是我所期望的。有人可以向我解釋爲什麼我得到最新的結果,我能做些什麼來解決它?這是有問題的代碼:PHP類數組問題
public static function getProduct($_row, $_value)
{
$stmt = _DB::init()->prepare("SELECT pid, name, quantity, price, cost
FROM products
WHERE $_row = ?"
);
if($stmt->execute(array($_value)))
{
while ($row = $stmt->fetch())
return $row;
}
}
$product = Class::getProduct('pid',1);
print_r($product);
當我打印以下陣列我得到每行有兩個結果,像這樣:
Array ([pid] => 1 [0] => 1 [name] => Boondoggle [1] => Boondoggle [quantity] => 12 [2] => 12 [price] => 9.9900 [3] => 9.9900 [cost] => 12.9900 [4] => 12.9900) Boondoggle
我只是想顯示關聯結果。我的功能有什麼問題?
你用什麼接口來連接到DB? – Xaerxess 2011-06-12 05:30:32