多字段查询,结果中访问不到属性
$this->load->database();
$this->db->select('title','keywords');
//$this->db->select('keywords');
$this->db->from('site');
$query = $this->db->get();
$data['query'] = $query;
$this->load->view('result',$data);
<?php foreach ($query->result() as $row):?>
<p>
<span style="color:#0f0"><?php echo $row->title?></span>
<span style="color:#0f0"><?php echo $row->keywords?></span>
</p>
<?php endforeach;?>
如果使用
$this->db->select('title','keywords');
在view中访问除第一个属性外就会说
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$keywords
Filename: views/result.php
Line Number: 11
如果用:
$this->db->select('title');
$this->db->select('keywords');
写2条语句就能访问到
郁闷,这是啥原因,
我看电子书教程里一次查好几个:
$this->db->select('url','name','clientid','people.surname AS client');
我的版本是1.7.2 xampp集成环境 5.3的php 汗,刚才去找了下源代码看了下
select的定义如下
function select($select = '*', $escape = NULL)
{
// Set the global value if this was sepecified
if (is_bool($escape))
{
$this->_protect_identifiers = $escape;
}
if (is_string($select))
{
$select = explode(',', $select);
}
foreach ($select as $val)
{
$val = trim($val);
if ($val != '')
{
$this->ar_select[] = $val;
if ($this->ar_caching === TRUE)
{
$this->ar_cache_select[] = $val;
$this->ar_cache_exists[] = 'select';
}
}
}
return $this;
}
这里只接受2个参数,select多字段查询是通过逗号分隔,跟sql语句一样,为啥翻译的那本书上要写
$this->db->select('url','name','clientid');
难道是ci版本问题? 这是个这本书(原书)的错误,已经记录在勘误表中,下次发布会更新的。
页:
[1]