Kani R Kani R - 7 months ago 9
PHP Question

How to return two table values using join query

Here i am using JOIN query, it will working super, after merging two table value I return one table only, I don't know how return both tables values. From this code task tables value is returned, task_employee table value I can't return, I don't know what will do??

$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);
}

Answer

The standard way of an inner join is:

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