【发布时间】:2012-01-16 23:17:03
【问题描述】:
Class Account extends CI_Model {
private $tbl_rest = array();
private $tbl_fields = array('bs_id', 'bs_name', 'bs_type', 'bs_sub');
function get_data($dataid){
$this->db->select( '*' );
$this->db->from( $this->tbl_name );
$this->db->where( $this->tbl_key, $id );
$query = $this->db->get();
if( $query->num_rows() > 0 )
{
foreach ($query->result() as $row)
{
$this->tbl_rest[] .= '<li id="'.$row->bs_id.'">'.$row->bs_name.'</li>';
}
echo( json_encode( array( 'tdata' => $this->tbl_rest ) ) );
} else {
echo( false );
}
}
}
当我像这样更改 $query->result() 时
'<li id="'.$row->$this->tbl_fields[0].'">'.$row->$this->tbl_fields[1].'</li>';
我开始收到错误“类的对象无法转换为字符串” 我的问题是:
可以将数组字符串转换为对象吗?
以及如何使$row->$this->tbl_fields[0]发生,所以我不必总是写字段的名称。
【问题讨论】:
标签: php codeigniter