[英]How to get a related record item from a different table
Firstly I have no idea about Codeigniter, though I am OK'ish with general PHP/MYSQL首先我不知道 Codeigniter,虽然我对一般的 PHP/MYSQL 很满意
I am trying to get an additional field [unlock_code] content from a related record.我正在尝试从相关记录中获取附加字段 [unlock_code] 内容。 I have a Sales table and a product table我有一个销售表和一个产品表
Here is the Error I get when I try it....这是我尝试时遇到的错误....
A PHP Error was encountered Severity: Notice Message: Undefined variable: unlock_code Filename: controllers/Paypal.php
// Load libraries
$this->load->library('AppSettings');
// Load models
$this->load->model('m_customers');
$this->load->model('m_products');
// Get customer and product data
$customer = $this->m_customers->by_cid($sale['cid']);
$product = $this->m_products->get_product($sale['pid']);
$configs = array(
'protocol' => $this->appsettings->get('email_method'),
'smtp_host' => $this->appsettings->get('smtp_host'),
'smtp_user' => $this->appsettings->get('smtp_username'),
'smtp_pass' => $this->appsettings->get('smtp_password'),
'smtp_port' => $this->appsettings->get('smtp_port'),
'smtp_crypto' => $this->appsettings->get('smtp_crypto'),
);
$this->load->library("email", $configs);
$this->email->set_newline("\r\n");
$this->email->to($customer['cust_email']);
$this->email->from(
$this->appsettings->get('support_email'),
$this->appsettings->get('support_contact_person')
);
$search = array(
'%CUSTOMER NAME%',
'%CUSTOMER EMAIL%',
'%PRODUCT NAME%',
'%PRODUCT PRICE%',
'%DOWNLOAD LINK%',
'%DOWNLOAD EXPIRY%',
'%UNLOCK CODE%',
);
$replace = array(
$customer['cust_firstname'].' '.$customer['cust_lastname'],
$customer['cust_email'],
$product['name'],
$product['price'],
site_url('download/'.$sale['download_code']),
$product['expiry'],
$product['unlock_code'],
);
Any help appreciated.任何帮助表示赞赏。
I figured it out.我想到了。
The query was not fetching the unlock code field from the products database for some reason.由于某种原因,该查询未从产品数据库中获取解锁代码字段。 So i changed it from...所以我把它从...
function get_product($pid) {
$res = $this->db->get_where($this->table, array('pid' => $pid), 1);
if ($res->num_rows() > 0) {
return $res->first_row('array');
}
return false;
}
To至
function get_product($pid) {
$res = $this->db->select('*')->get_where($this->table, array('pid' => $pid), 1);
if ($res->num_rows() > 0) {
return $res->first_row('array');
}
return false;
}
That sorted it.这样就整理好了。
Thank you for the offers of help感谢您提供帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.