Welcome Guest, Not a member yet? Register   Sign In
Problem retreiving results from database
#1

[eluser]jonhurlock[/eluser]
Hi all,

When I go to the following URL http://mydomain.com/boats/index on mysite I get the following error:
Code:
Fatal error: Class 'CI_DB_result' not found in /the-path-to-my-directory/system/database/drivers/mysql/mysql_result.php on line 27
I can insert results in to my database. However, when I go to return results from the database, the error message above appears. Any help would be appreciated. I have included the relevant pieces of code below. I can't seem to see anything wrong with the code though, is my mysql_result.php file buggered?

Best,

Jon

Controller:boats.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Boats extends CI_Controller {

public function __construct()
{
  parent::__construct();
  $this->load->model('boats_model');
}

public function index()
{
   $data['title'] = 'Mumbles Fleet';
   $data['boats'] = $this->boats_model->get_boats();
   if (empty($data['boats']))
   {
    $this->load->view('template/header', $data);
    $this->load->view('template/footer');
   }
   $this->load->view('template/header', $data);
   $this->load->view('boat_management/show_boats', $data);
   $this->load->view('template/footer');
}
}
Model:boats_model.php
Code:
<?php
class Boats_model extends CI_Model {

public function __construct()
{
  $this->load->database();
}

public function get_boats($boat_id=FALSE)
{
  if ($boat_id == FALSE)
  {
   $query = $this->db->get('boats');
   return $query->result_array();
  }
  $query = $this->db->get_where('boats', array('id' => $boat_id));
  return $query->row_array();
}


}
View:boat_management/show_boats.php
Code:
<?php foreach ($boats as $boat): ?>
    <h2>&lt;?php echo $boat['name'] ?&gt;</h2>
    <div id="main">
        &lt;?php echo $boat['type'] ?&gt;(&lt;?php echo $boat['row_type'] ?&gt;)<br />
&lt;?php echo $boat['description'] ?&gt;
    </div>
&lt;?php endforeach ?&gt;
#2

[eluser]bobbob[/eluser]
try $this->load->database(); in the controller before loading the model as I have sometimes had issues loading models etc inside models
#3

[eluser]jonhurlock[/eluser]
Nope, doesn't seem to make any difference Sad
#4

[eluser]InsiteFX[/eluser]
Do a var_dump to see if you are returning any records, being as you are checking for that in your model method!
You should be checking in your model method for the num_rows() returned.
Code:
var_dump($this->boats_model->get_boats());




Theme © iAndrew 2016 - Forum software by © MyBB