Php 如何从不同的表中获取相关记录项
首先,我不知道Codeigniter,尽管我对普通的PHP/MYSQL还行 我正试图从相关记录中获取附加字段[unlock_code]内容。我有一张销售表和一张产品表 这是我尝试时遇到的错误Php 如何从不同的表中获取相关记录项,php,codeigniter,Php,Codeigniter,首先,我不知道Codeigniter,尽管我对普通的PHP/MYSQL还行 我正试图从相关记录中获取附加字段[unlock_code]内容。我有一张销售表和一张产品表 这是我尝试时遇到的错误 感谢您的帮助。我想出来了 由于某种原因,查询未从产品数据库中获取解锁代码字段。所以我把它从 function get_product($pid) { $res = $this->db->get_where($this->table, array('pid' => $pid)
感谢您的帮助。我想出来了 由于某种原因,查询未从产品数据库中获取解锁代码字段。所以我把它从
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;
}
到
那就对了
谢谢你提供的帮助如果你
var\u dump($product->result())
,解锁代码输出了吗?我会试试的谢谢你没有乐趣我很震惊你能发布你的代码吗<代码>$this->m_products->get_product()函数get_product($pid){$res=$this->db->get_where($this->表,数组('pid'=>$pid),1);if($res->num_rows()>0){返回$res->第一行('array');}返回false;}
// 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'],
);
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;
}