Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter中函数的SQL返回行_Php_Sql_Codeigniter - Fatal编程技术网

Php Codeigniter中函数的SQL返回行

Php Codeigniter中函数的SQL返回行,php,sql,codeigniter,Php,Sql,Codeigniter,我试图从一个新的SQL查询中获取整行值 如何生成函数 Select * from table1 t1,table2 t2,table3 t3 where t1.t1_id=t2.t1_id and t3.id=t2.t3_id 对这样的事情: 在模型页面中 public function getID_researcher($lastname){ $query = $this->db->get_where('researcher', array('lastname' => $l

我试图从一个新的SQL查询中获取整行值

如何生成函数

Select * from table1 t1,table2 t2,table3 t3 where t1.t1_id=t2.t1_id and t3.id=t2.t3_id
对这样的事情: 在模型页面中

public function getID_researcher($lastname){
$query = $this->db->get_where('researcher', array('lastname' => $lastname));
return $query->row_array();
} 
我需要根据表1中的lastname返回一行结果

这里要澄清的是,“研究者”是它获取数据的表,但我想要的是我获取数据的新SQL

我试过这个,但还是出错了

public function getID_researcher($lastname){
$sql = = $this->db->query('Select * from table1 t1,table2 t2,table3 t3 where t1.t1_id=t2.t1_id and t3.id=t2.t3_id');

$query = $this->db->get_where($sql, array('lastname' => $lastname));
return $query->row_array();
} 
要使用此查询,请执行以下操作:

Select * from table1 t1,table2 t2,table3 t3 where t1.t1_id=t2.t1_id and t3.id=t2.t3_id
您可以尝试使用active record db“join”,如下所示:

$this->db->from('table1 t1');
$this->db->join('table2 t2', 't1.t1_id = t2.t1_id', 'left');
$this->db->join('table3 t3', 't3.id = t2.t3_id', 'left');
$this->db->where('lastname', $lastname);
$query = $this->db->get();
$c = 0;
foreach($query->result() as $q){
  $result[$c]['name'] = $q->lastname;
  // put move variable here
$c++;
}
return $result;

希望这些帮助

什么是
get_在哪里
返回,它是数组吗?@miltonb它是数组。但正如你所看到的,“研究者”是它得到的表格。但我想从新的sql中获取数据。当我查看我的查看页面时,它会显示未定义的索引:年龄等。