Once the inner loop has gone through all the rows in [font=monospace]$result1[/font] it's at the end. The next time you get to the inner loop, it's still at the end.
$selected_ids = array();
while($row1 = mysql_fetch_assoc($result1))
{
$selected_ids[] = $row1['lab_id'];
}
while($row2 = mysql_fetch_assoc($result2);
{
....
if(in_array($row2['lab_id'], $selected_ids))
{
....
}
}
Also, note that use of the MySQL extension in new development is discouraged.