Php 使用PDO返回单个值集而不是数组

Php 使用PDO返回单个值集而不是数组,php,mysql,pdo,Php,Mysql,Pdo,这个网站上的一个非常好的人帮我写了下面的脚本(而且效果不错) 例如,使用PDO::fetchAll $stmt->execute(); $arrResults = $stmt->fetchAll(); //$arrResults will be multidimensional //This will echo the first sideimage echo $arrResults[0]['sideimage']; 如果要回显侧图像(即:所有行)的所有值,则必须遍历结果 for

这个网站上的一个非常好的人帮我写了下面的脚本(而且效果不错)


例如,使用PDO::fetchAll

$stmt->execute();
$arrResults = $stmt->fetchAll();

//$arrResults will be multidimensional
//This will echo the first sideimage
echo $arrResults[0]['sideimage'];
如果要回显
侧图像
(即:所有行)的所有值,则必须遍历结果

foreach($arrResults as $arrRow) {
   echo $arrRow['sideimage'] . PHP_EOL;
}
链接
您应该使用循环

如果不想使用循环,请尝试

你可以用



对于多行,您必须循环查看结果您的答案是正确的,但使用
fetch
毫无意义。他应该使用
fetchAll
。非常正确,将进行修改。感谢@debflav尝试使用以下代码,但没有得到任何$stmt=$dbh->prepare('SELECT title,instructions,sideimage FROM dowdb_recipe_repository,title=:title ORDER BY rating DESC');$stmt->bindParam(':title',$_POST['title'],PDO::PARAM_STR,50);$stmt->execute()$行=$stmt->fetchAll(PDO::FETCH_ASSOC);while($row=$stmt->fetch()){echo$row[0]['instructions'];}删除
while
循环,并
foreach
通过
$row
现在使用(无结果)$stmt=$dbh->prepare('SELECT title,instructions,sideimage FROM dowdb_recipe(repository WHERE title=:title ORDER BY rating DESC');$stmt->bindParam(':title',$_POST['title'],PDO::PARAM_STR,50);$stmt->execute()$行=$stmt->fetchAll(PDO::FETCH_ASSOC);foreach($arrow作为$arrow的行){echo$arrow[0]['instructions'].PHP_EOL;}
foreach($arrResults as $arrRow) {
   echo $arrRow['sideimage'] . PHP_EOL;
}
while($abc = $stmt->fetch())
{
  print_r($abc);
}
$data = $stm->fetchAll();
$res = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo $res[0]['sideimage'];
foreach($res as $key=>$value) {
    $image_val = $value['sideimage'];
}