我设法编辑了从教程中复制的代码
public function viewItem(){
self::conn();
try {
$sql = "SELECT * FROM dbo.guitar WHERE id=:id";
$q = self::$db->prepare($sql);
$q->execute(array(':id' => $this->id));
$row = $q->rowCount();
if ($row == 0)
{
echo 'no records found.';
}
else
{
$results = $q->fetchAll(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE,
"Guitar",
array('id', 'make', 'model', 'colour', 'price'));
}
}catch (Exception $e){
print "Error!: " . $e->getMessage();
}
return $results;
}
根据Id,我获取了所有数据,我的问题是如果我希望颜色全部显示怎么办。