Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sakthikamal opened this issue Dec 30, 2019 · 2 comments
Closed

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

sakthikamal opened this issue Dec 30, 2019 · 2 comments

Comments

@sakthikamal
Copy link

sakthikamal commented Dec 30, 2019

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

@canc
Copy link
Contributor

canc commented Jan 1, 2020

you should state the exact table (which includes invoiceId) in your where statement.
i.e. $this->db->where('i.invoiceId', $invoiceId);

@sakthikamal
Copy link
Author

Thanks alot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants