如何通过INNER JOIN获得这些信息?

时间:2019-03-11 06:47:59

标签: php mysql mysqli

<?php 
$employee_id = $_SESSION['employee_id'];
$empquery= mysqli_query($db,"select * from employees WHERE `employee_id` = '$employee_id'");
While ($rowemp= mysqli_fetch_assoc($empquery))
{
    $branch_name = $rowemp['branch_name'];
}
$query= mysqli_query($db,"select * from asset_evaluation WHERE `status` = 'NEW' AND `branch_name` = '$branch_name' ");
while($row= mysqli_fetch_assoc($query))
{   
    $supplier_cnic = $row['supplier_cnic'];

    $supplier = mysqli_query($db, "select `supplier_name` FROM suppliers 
        WHERE `supplier_cnic` = '$supplier_cnic' ");
    $outputrow = $supplier->fetch_assoc();  
    $suppplier_name = $outputrow['supplier_name'];

    //echo all values
}

1 个答案:

答案 0 :(得分:-2)

这不是火箭科学...

SELECT c.olumns
     , y.ou
     , a.ctually
     , w.ant
  FROM employees e
  JOIN asset_evaluation a
    ON a.branch_name = e.branch_name
  JOIN suppliers s
    ON s.supplier_cnic = a.supplier_cnic
 WHERE e.employee_id = :employee_id
   AND a.status = 'NEW'