I have added some code to model/account/customer.php
What I would now like to do is have parts of the code replaced with variables from a database table.
E.g.
<?
$from = "text from database goes here";
?>
which would come from the database from a table called 'tablename' from a column called 'textformessage'
How might I go about collecting that database table and then spitting out the value into the code?
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:
Or if you want to carry an argument over to the function you can do it like this (including a WHERE /AND )
Your control would look something like this (with the argument + foreach loop to deal with the object array):
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:
You can simply echo the value straight from the $query variable like this:
And the model function will look like this:
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;
}
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;
}
Code: Select all
$query = $this->model_catalog_product->yourFunction($argument_value);
foreach ($query as $value) {
$this->data['value'] = $value['field_id'];
}
Code: Select all
<?php echo $value;?>
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'];
}
Code: Select all
$query = $this->model_catalog_product->yourFunction($argument_value);
$this->data['value'] = $query['field_id'];
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;
}
Thank you very much for the explination. I will try and get my head around it.
Right now I don't need to echo anything out into the html / view. I just need to run a script / process behind the scenes that triggers something but I want the option and value of it to come from database settings that the user can control in the admin.
Right now I don't need to echo anything out into the html / view. I just need to run a script / process behind the scenes that triggers something but I want the option and value of it to come from database settings that the user can control in the admin.
Who is online
Users browsing this forum: No registered users and 111 guests