view raw
Chathurika Chathurika - 11 months ago 46
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.



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

Please help !


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];

instead you only set

$array = mysql_fetch_array($result1);