代码之家  ›  专栏  ›  技术社区  ›  prattom

从杂货crud中的mysql数据库获取列

  •  0
  • prattom  · 技术社区  · 7 年前

    我想创建一个下拉列表,其中包含来自杂货店积垢数据库的修改后的列数据。我的代码如下

    $this->db->select($column);
    $temp = $this->db->get($table);
    $temp1 = array();
    foreach ($temp as $row)
    {
        $temp1[] = $row[$column];
    }
    

    但是这个代码不起作用。我出错了 undefined index $column 错误。我在哪里犯错误?我不能用杂货残渣 set_relation 因为我需要在将数据库列数据传递到下拉列表之前修改它。

    1 回复  |  直到 7 年前
        1
  •  0
  •   prattom    7 年前

    public function get_column($table, $column, $condition=null, $value=null)
    {
        $this->db->select($column);
        if ($condition != null)
        {
            $this->db->where($condition, $value);
        }
        $temp = $this->db->get($table);
    
        $temp_array = array();
        foreach ($temp->result() as $row)
        {
            $temp_array[] = $row->$column;
        }
        return $temp_array;
    }
    
    推荐文章