使用数组的Codeigniter活动记录查询

时间:2017-01-18 08:08:41

标签: php mysql arrays codeigniter activerecord

我正在使用此查询:

$lang就像这个Array ( [0] => Afrikaans [1] => English )

    $this->db->select('id');
    $this->db->from('language');
    $this->db->where_in('language',$lang);
    $query = $this->db->get();
    $l_id =$query->result_array();  

对于此查询,当我使用print_r($l_id)时,我得到这样的输出:

Array ( [0] => Array ( [id] => 1 ) [1] => Array ( [id] => 21 ) )  

但我需要这样的事情:

Array ( [0] =>  1  [1] =>  21 )   

有人请帮我这样做。感谢

2 个答案:

答案 0 :(得分:2)

试试这个......

var cellLabelTextArray: [String] = [] // populate this with data for each cell

@IBAction func plusBtnAction(_ sender: UIButton) {

     var cell:TableViewCell = self.tebleView.dequeueReusableCell(withIdentifier: "Cell")! as UITableViewCell as! TableViewCell

     let indexPath = IndexPath(row: sender.tag, section: 0)

     var cellLabelText = cellLabelTextArray[indexPath.row]
     cellLabelText = "\(Int(cellLabelText) + 1)"

     cellLabelTextArray[indexPath.row] = cellLabelText

     if let visiblePaths: [IndexPath] = self.tableView.indexPathsForVisibleRows {
        if visiblePaths.contains(indexPath) {
            self.tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
        }
    }
}

例如:

$this->db->select('id');
$this->db->from('language');
$this->db->where_in('language',$lang);
$query = $this->db->get();
$l_id =$query->result_array();  
foreach($l_id as $key=>$value)
{
   $ids[] = $value['id'];
}
print_r($ids);

答案 1 :(得分:0)

替换:

 $l_id =$query->result_array();

使用:

 $l_id =$query->result();

或尝试

 $l_id =$query->row();
相关问题