Welcome Guest, Not a member yet? Register   Sign In
Error connecting to Database via class
#12

[eluser]xzela[/eluser]
aha!
I think i got it,

Try this:
Modify your Joes_class file:
Code:
class Joes_class {
var $ci; //defines a place for the instance;    
function Joes_class() {
  $this->ci =& get_instance(); //get's an instance of the class;
  $this->ci->load->database(); //loads the database into the instances;
}    
function get_from_database() {
  $industry = "SELECT * FROM test_table";
  $result = $this->ci->db->query($industry); //call the database method query() within the instance;
  return $result->result_array(); //this will return an array;  
}
}

I would highly recommend NOT using this method of getting data from a database. You've just created a model but in a difficult way. Another way to do this would be to use the Model method:

Create a file in the /system/application/model directory called 'industry_model.php';
copy this code into that file
Code:
class Industry_model extends Model {
function Industry_model() {
  $this->load->database(); //loads the database class
}

function get_industry() {
   $query = $this->db->query('select * from industry where parentid = 0'); //run the query
   return $query->result_array(); //returns an array of data
}
}


Now in your Register controller change this line:
Code:
//$this->load->library('Joes_class');
$this->load->model('industry_model');

And to call the get_industry() method, change this line
Code:
//$industry_names = $this->joes_class->get_industry();
$industry_names = $this->industry_model->get_industry();

that should do it.

let me know if anything goes wrong.


Messages In This Thread
Error connecting to Database via class - by El Forum - 01-26-2009, 05:25 PM
Error connecting to Database via class - by El Forum - 01-26-2009, 05:49 PM
Error connecting to Database via class - by El Forum - 01-26-2009, 06:03 PM
Error connecting to Database via class - by El Forum - 01-26-2009, 06:17 PM
Error connecting to Database via class - by El Forum - 01-26-2009, 06:36 PM
Error connecting to Database via class - by El Forum - 01-26-2009, 06:49 PM
Error connecting to Database via class - by El Forum - 01-26-2009, 07:11 PM
Error connecting to Database via class - by El Forum - 01-26-2009, 07:21 PM
Error connecting to Database via class - by El Forum - 01-26-2009, 07:38 PM
Error connecting to Database via class - by El Forum - 01-26-2009, 07:42 PM
Error connecting to Database via class - by El Forum - 01-26-2009, 07:45 PM
Error connecting to Database via class - by El Forum - 01-26-2009, 09:10 PM
Error connecting to Database via class - by El Forum - 01-27-2009, 06:09 PM
Error connecting to Database via class - by El Forum - 01-27-2009, 06:59 PM
Error connecting to Database via class - by El Forum - 01-27-2009, 07:09 PM
Error connecting to Database via class - by El Forum - 01-27-2009, 07:46 PM
Error connecting to Database via class - by El Forum - 01-27-2009, 07:50 PM
Error connecting to Database via class - by El Forum - 01-27-2009, 08:28 PM
Error connecting to Database via class - by El Forum - 01-27-2009, 08:33 PM
Error connecting to Database via class - by El Forum - 01-27-2009, 09:47 PM



Theme © iAndrew 2016 - Forum software by © MyBB