我希望从一个数组中删除重复项,我使用while循环从存储过程调用。删除从while循环中获取的重复项
// Prepare stored procedure call
$sth = $dbh->prepare('CALL sp_get_recipes()');
// Call the stored procedure
$res = $sth->execute();
if ($res){
while($row = $sth->fetchObject()){
echo $row->Recipe; // I would like to echo this row just once.
echo '<ul class="recipe-body"><li>'.$row->Ingredient." ".$row->Quantity." ".$row->UoM.'</li></ul>';
}
// Close connection
$dbh = null;
}else{
$arr = $sth->errorInfo();
echo "Execution failed with MYSQL: " . $arr[0] . "\n";
die();
}
我的理解是我的echo $ row-> Recipe;必须以某种方式自己存在。我一直在研究array_unique来回显值,但我似乎无法完全弄清楚。如果有人能指引我朝着正确的方向发展,那就太好了。
UPDATE 感谢所有的答复我已经修复了存储过程以返回唯一行。
如何从程序返回唯一行? – 2012-03-15 14:45:59