由于某种原因,我返回的数组不是我所期望的。有人可以向我解释为什么我得到最新的结果,我能做些什么来解决它?这是有问题的代码: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