Skip to content

How to join 3 Tables using $db->join fucntion #873

Closed
@sakthikamal

Description

@sakthikamal

function oneInvoice($invoiceId) {
$this->db->where('invoiceId', $invoiceId);
$this->db->join("customers c", "i.cusName = c.cusName");
$this->db->join("payment p", "i.invoiceId=p.invoiceId");
$viewOne = $this->db->getOne ("invoice i", null, "c.cusName, c.cusMobile, c.cusEmail, c.cusAddress, i.function, i.fromDate, i.total, p.amount, p.balance, p.paymentDate");
if ($this->db->count > 0) {
return $viewOne;
}
}

Show the browser like this

Fatal error: Uncaught Exception: Column 'invoiceId' in where clause is ambiguous query: SELECT * FROM invoice i JOIN customers c on i.cusName = c.cusName JOIN payment p on i.invoiceId=p.invoiceId WHERE invoiceId = ? LIMIT 1 in D:\xampp\htdocs\sakthi\billing\classes\MysqliDb.php:2006 Stack trace: #0 D:\xampp\htdocs\sakthi\billing\classes\MysqliDb.php(1594): MysqliDb->_prepareQuery() #1 D:\xampp\htdocs\sakthi\billing\classes\MysqliDb.php(738): MysqliDb->_buildQuery(1) #2 D:\xampp\htdocs\sakthi\billing\classes\MysqliDb.php(764): MysqliDb->get('invoice i', 1, '*') #3 D:\xampp\htdocs\sakthi\billing\classes\fun_class.php(79): MysqliDb->getOne('invoice i', NULL, 'c.cusName, c.cu...') #4 D:\xampp\htdocs\sakthi\billing\view-invoice.php(10): auth->oneInvoice('1') #5 {main} thrown in D:\xampp\htdocs\sakthi\billing\classes\MysqliDb.php on line 2006

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions