What code exactly did you add to the model? The model file is for running query's on the database. The control is used for setting up variables to be echoed on to the HTML (or it can query the database , skipping the model entirely)
Your model function could look something like this:
Code: Select all
public function yourFunction() {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "yourtable" ORDER BY field_id);
return $query->rows;
}
Or if you want to carry an argument over to the function you can do it like this (including a WHERE /AND )
Code: Select all
public function yourFunction($argument_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "yourtable WHERE field_id = '" . (int)$argument_id . "' ORDER BY id");
return $query->rows;
}
Your control would look something like this (with the argument + foreach loop to deal with the object array):
Code: Select all
$query = $this->model_catalog_product->yourFunction($argument_value);
foreach ($query as $value) {
$this->data['value'] = $value['field_id'];
}
Now you simply echo the value in the HTML
If you have more than one value to echo then you set up an array in the control and iterate through it in the HTML with php's FOR EACH LOOP.
Important: Notice the query in the model file uses a wildcard (*). You may not need this if you only have one or two values you want to grab. In this case you don't need to have this in your control:
Code: Select all
foreach ($query as $value) {
$this->data['value'] = $value['field_id'];
}
You can simply echo the value straight from the $query variable like this:
Code: Select all
$query = $this->model_catalog_product->yourFunction($argument_value);
$this->data['value'] = $query['field_id'];
And the model function will look like this:
Code: Select all
public function yourFunction($argument_id) {
$query = $this->db->query("SELECT field_id FROM " . DB_PREFIX . "yourtable WHERE field_id = '" . (int)$argument_id . "'");
return $query->row;
}