如何使用连接查询返回两个表值

时间:2016-04-16 15:07:31

标签: php php-5.6

这里我使用JOIN查询,它会超级工作,合并两个表值后我只返回一个表,我不知道如何返回两个表值。从这段代码任务表返回值,task_employee表值我不能返回,我不知道会怎么做??

$dapartment = $_POST['department'];
$q = mysql_query("SELECT * FROM task_employee te, task t WHERE te.emp_designation='$dapartment' AND te.emp_id = t.t_assign_to");
$data = array();
while($r = mysql_fetch_assoc($q)){
    $data[] = $r;
}  
$count = sizeof($data);
if($count > 0){ 
    $return=array('status'=>'success','count'=>sizeof($data),'data'=>$data);
    echo json_encode($return);
}else{
    $return=array('status'=>'not-found','count'=>sizeof($data),'data'=>$data);
    echo json_encode($return);
}

1 个答案:

答案 0 :(得分:0)

内部联接的标准方式是:

SELECT * FROM task_employee te JOIN task t ON te.emp_id = t.t_assign_to WHERE te.emp_designation='$dapartment'