Answer the question
In order to leave comments, you need to log in
How to join from another table?
I must to join company_type add get All datas from companies.
index.php
include 'Company.php';
$company = new Company();
$companyData = $company->getCompanyById($companyId);
var_dump($companyData);
class Company
{
public function getCompanyById($companyId)
{
$sql="SELECT companies.id, companies.company_type_id, companies.name, companies.email
FROM companies
INNER JOIN company_type
ON company_type.name = companies.company_type_id WHERE companies.id = $companyId ";
$query = $this->db->pdo->prepare($sql);
$query->bindValue(':company_id', $companyId);
$query->execute();
$result = $query->fetch(PDO::FETCH_OBJ);
return $result;
}
}
id | name | email | company_type_id
id | company_type
Answer the question
In order to leave comments, you need to log in
SELECT companies.id, company_type.company_type, companies.email, companies.name, companies.company_type_id
FROM companies
INNER JOIN company_type
ON companies.company_type_id=company_type.id WHERE companies.id = :company_id;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question