Ayn better way to do that?

I need to display all users from a company and users details (fullname, age, position).

I am wondering if the below method is a correct way to display 15 employees per page. In this method on each page 16 queries are executed and this is what I am worried about. Is that far too much or is it still ok?

table employees
id | userid | companyid | position

table users
userid | firstname | lastname | age | email | password …


$employees=mysql_query("SELECT userid FROM employees WHERE companyid='$companyid' LIMIT $paginationLimit ");
while($rowemployees=mysql_fetch_assoc($employees){
  $userid=$rowemployees[userid];
  $employeeDetails=mysql_query("SELECT * FROM users WHERE userid='$userid'");
  while($rowEmployeeDetails=mysql_fetch_assoc($employeeDetails){
    $firstname=$rowEmployeeDetails[firstname];
    $lastname=$rowEmployeeDetails[lastname];
    $age=$rowEmployeeDetails[age];
    $position=$rowEmployeeDetails[position];
  }
}

I missed something. I need to get from table employees also position. Also in subquery there is no while. So the query is:


$employees=mysql_query("SELECT userid, position FROM employees WHERE companyid='$companyid' LIMIT $paginationLimit ");
while($rowemployees=mysql_fetch_assoc($employees){
  $userid=$rowemployees[userid];
  $position[]=$rowemployees[position];
  $employeeDetails=mysql_query("SELECT * FROM users WHERE userid='$userid'");
  $rowEmployeeDetails=mysql_fetch_assoc($employeeDetails)
    $firstname[]=$rowEmployeeDetails[firstname];
    $lastname[]=$rowEmployeeDetails[lastname];
    $age[]=$rowEmployeeDetails[age];
} 

You should be using a join to get the info from the users table!!!

SELECT e.userid, e.position, u.firstname, u.lastname, u.age
FROM employees as e
JOIN users as u
ON e.userid = u.userid
WHERE e.companyid = ‘$companyid’ LIMIT $paginationLimit;

please use more descriptive thread titles so folks know what the thread is about.