Chathurika Chathurika - 6 months ago 11
MySQL Question

MYSQL Query fail to select possible result

I want to get all emp_ids of employees which is manager_id equal to login user_id. But why this query show only first result of the column. I could not able to find the problem.

$userID=$_SESSION['userID'];

var_dump($userID);

$result1 = mysql_query("SELECT emp_id FROM employee where manager_id='$userID' ORDER BY emp_id");
$array = mysql_fetch_array($result1);
$id1=$array['emp_id'];





Please help !

Answer

You should loop over the result

and eg: you can store all the empID in an array

$cnt = 0;
while ($row = mysql_fetch_array($result1)) {
    echo "ID: " . $row[0] ;  
    $myArrayOfEmpID[$cnt] = $row[0];
    $cnt++;
}

instead you only set

$array = mysql_fetch_array($result1);
 $id1=$array['emp_id'];
Comments