Welcome Guest, Not a member yet? Register   Sign In
fetching mysql info
#1

[eluser]_Smilie_[/eluser]
Hi,
So this is my controller:
Code:
$data['query'] = $this->db->get('host');
   $data['row'] = $this->db->where('host_queued =', 1);
   $data['pendingHosts'] = $this->db->count_all_results('host');
   $data['tableTitle'] = 'Pending hosts in database';
   $this->load->view('global/header');
   $this->load->view('global/userinfo');
   $this->load->view('host_edit', $data);

Alright, so this works flawlessly, however I would like my row to be the actual array, so i tried:
$data['row'] = $this->db->where('host_queued =', 1)->row_array();
It didn't make much sense in my head, but had no idea on how else to do this in the controller. I perform the edit and wupti, page refresh produces:
Fatal error: Call to undefined method CI_DB_mysql_driver::row_array() in C:\xampp\htdocs\whr\application\controllers\host.php on line 43

Any tips?
#2

[eluser]CroNiX[/eluser]
Because you already executed your query using get() above, so the where() is the start of a new query, but you don't execute it with get() so it doesn't know what row_array() is.
#3

[eluser]_Smilie_[/eluser]
I think i might have misunderstood the documentation then.

So if I want to combine the two, what can I do? (I still want it as an ACTIVE record)
#4

[eluser]CroNiX[/eluser]
The where() would have to come before the get(). You put your select(), where(), join(), etc, before the get() because get() will execute the compiled query.
Code:
$row = $this->db
  ->where('host_queued', 1) //don't really need the =, that is the default
  ->get('host')
  ->row_array();
$data['query'] = $this->db->last_query(); //store the last query that was run
$data['row'] = $row; //store the result row
#5

[eluser]_Smilie_[/eluser]
Thanks, much appreciated.




Theme © iAndrew 2016 - Forum software by © MyBB