我能够以数组形式从我的数据库表中获取值。但我不知道如何在我的 <table><tr><td>// values of subjectId comes here </td>
<td>//values of subject Name comes here</td></tr></table>
. 我想在我的标签中一一迭代所有字段值。
在数组中我得到这样的值:
FIctionNon FIctionArray ( [0] => stdClass Object ( [subject_id] => 1 [subject_name] => FIction [creater_id] => 1 [created_date] => 2012-10-07 16:49:12 [update_id] => 1 [updated_date] => 2012-10-07 16:49:12 ) [1] => stdClass Object ( [subject_id] => 2 [subject_name] => Non FIction [creater_id] => 1 [created_date] => 2012-10-07 16:49:12 [update_id] => 1 [updated_date] => 2012-10-07 16:49:12 ) )
我获取输出的代码如下:
$con = new connection();
$info = new Subdetails_setup($con);
$results = $info->getSubjectInfo();
print_r($results);
我的方法看起来像这样:
function getSubjectInfo()
{
$sub_info = $this->con->prepare("SELECT * FROM subjectdetails");
$sub_info->execute();
$results = $sub_info->fetchAll(PDO::FETCH_OBJ);
foreach ($results as $key)
{
echo $key->subject_name;
}
// Return the result array
return $results;
}
我的桌子是。“主题详情”
subject_id int(3) NO PRI NULL auto_increment
subject_name varchar(150) NO NULL
creater_id int(5) NO NULL
created_date datetime NO NULL
update_id int(5) NO NULL
updated_date datetime NO NULL
. 请帮助我。