如何从不同的表中获取相关的记录项

  • 本文关键字:获取 记录 php codeigniter
  • 更新时间 :
  • 英文 :


首先,我对Codeigniter一无所知,尽管我对通用的PHP/MYSQL 很满意

我正在尝试从相关记录中获取一个额外的字段[unlock_code]内容。我有一张销售表和一张产品表

这是我尝试时得到的错误…

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("rn");
$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'],
);

感谢您的帮助。

我想明白了。

由于某种原因,查询未从产品数据库中获取解锁代码字段。所以我把它从。。。

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;
}

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;
}

这就解决了问题。

感谢提供的帮助

相关内容

  • 没有找到相关文章

最新更新