2 回答

TA贡献1799条经验 获得超9个赞
您在 foreach 循环的帮助下查询数据库的方法是错误的。正确的方法是在查询中使用连接:
从您的函数getDataOneColumn()中,您仅使用snippet_id 值,您可以使用它来创建连接:
public function getDataOneColumn($table, $col1_name, $col1_value, $limit, $start)
{
$this->db->select("t1.*,t2.*")
->where("t1.$col1_name", $col1_value)
->join("snippets t2","t1.snippet_id=t2.id")
->limit($limit, $start);
$query = $this->db->get("$table t1");
$result = $query->result();
return $result;
}
注意:在您的示例$tag_id=$col1_value中,请使用更适合的任何变量名称。
那么你的第二个功能get_tags()就完全没有必要了。

TA贡献1864条经验 获得超6个赞
我希望这能帮到您
public function get_tags($params = array(), $tag_id)
{ $result = array();
$snippetstagdata = $this->getDataOneColumn("snippets_tags","tag_id",$tag_id);
foreach ($snippetstagdata as $data) {
$this->db->where('id',$data['snippet_id']);
if(isset($params) && !empty($params))
{
$this->db->limit($params['limit'], $params['offset']);
}
$result[$data['snippet_id']] = $this->db->get('snippets')->result_array();
}
return $result;
}
和
public function getDataOneColumn($table, $col1_name, $col1_value)
{
return $this->db->get_where($table,array($col1_name=>$col1_value))->result_array();
}
- 2 回答
- 0 关注
- 169 浏览
添加回答
举报