0

I have run this code to show all columns from database table.

    public function autorun()
  {
    $mysql_query = "show columns from store_accounts";
    $query = $this->db->simple_query($mysql_query);
    foreach ($query->result() as $row) {
      $column_name = $row->Field;
      echo $column_name; exit;
    }
  }

but it gives me that error.

Call to undefined method mysqli_result::result()

Waqas Ahmad
  • 426
  • 1
  • 3
  • 16
  • simple_query will not return any result, it will check and return TRUE & FALSE only\ – M.Hemant Apr 03 '19 at 11:18
  • you need to use $this->db->query('YOUR QUERY HERE'); to get result – M.Hemant Apr 03 '19 at 11:20
  • @M.Hemant $query = $this->db->query("show columns from store_accounts"); $mysql_query = $query->result(); and then i write $mysql_query in foreach but it shows one column – Waqas Ahmad Apr 03 '19 at 11:23

1 Answers1

2

Try this,simple_query will only return true or false according to your query

public function autorun() {
        $mysql_query = "show columns from store_accounts";
        $query = $this->db->query($mysql_query);
        foreach ($query->result() as $row) {
            $column_name = $row->Field;
            echo $column_name.'<p>';
        }
        die;
    }
M.Hemant
  • 2,345
  • 1
  • 9
  • 14