【问题标题】:getting column from mysql database in grocery crud从杂货店杂货中的mysql数据库获取列
【发布时间】:2018-07-04 11:48:04
【问题描述】:

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

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

但是这段代码不起作用。我收到错误undefined index $column 错误。我在哪里犯错?我不能使用杂货杂货set_relation api,因为我需要在将数据库列数据传递到下拉列表之前对其进行修改。

【问题讨论】:

    标签: php grocery-crud


    【解决方案1】:

    我的代码出错了。杂货杂货的工作代码如下

    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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-20
      相关资源
      最近更新 更多