如何使用代码点火器
读取review_text列值在这行代码中,igniter给出了以下错误
<p class="excerpt" align="justify"><?=$review->REVIEW_TEXT;?></p>
在网页上显示时给出错误
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: views/reviewpage.php
Line Number: 83
这是我的表
CREATE TABLE `techreview`.`trn_reviews` (
`review_id` int(10) unsigned NOT NULL auto_increment,
`review_url` varchar(200) collate latin1_general_ci NOT NULL,
`review_text` text collate latin1_general_ci NOT NULL,
`review_dt` date NOT NULL,
PRIMARY KEY (`review_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
这是我的模型方法
function getReviewDetails($url){
$this->db->select('REVIEW_URL,REVIEW_TEXT');
$whereCondition = $array = array('REVIEW_URL' =>$url);
$this->db->where($whereCondition);
$query = $this->db->get("trn_reviews");
return $query->result();
}
答案 0 :(得分:0)
我假设你正在做这样的事情?
<?php
$review = $this->my_model->getReviewDetails("url_text_here");
?>
<p class="excerpt" align="justify"><?=$review->REVIEW_TEXT;?></p>
你不应该遍历结果集吗?
<?php
$review = $this->my_model->getReviewDetails("url_text_here");
foreach($review as $row) {
?>
<p class="excerpt" align="justify"><?=$row->review_text;?></p>
<?php
}
?>
如果您的查询只返回1行,则可以使用$query->row()
方法:
// in your model
function getReviewDetails($url){
$this->db->select('REVIEW_URL,REVIEW_TEXT');
$whereCondition = $array = array('REVIEW_URL' =>$url);
$this->db->where($whereCondition);
$query = $this->db->get("trn_reviews");
return $query->row();
}
// in your view
<?php
$review = $this->my_model->getReviewDetails("url_text_here");
?>
<p class="excerpt" align="justify"><?=$review->review_text;?></p>