mysqli查询了一会儿和foreach

Here's my code:

                    while($listAll = $listAllHere->fetch_assoc()) {                         
                        $whos = array();
                        $j_out = array();

                        $whos[] = $listAll['user_id'];
                        $j_out[] = $listAll['j_out'];


                        foreach ($j_out as $time) {
                            $timeleft = $time - $now;
                            if ($timeleft >= 0) {
                                foreach ($whos as $ids) {
                                    echo "<div class=\"col-xs-3\"><a href=\"#\" class=\"btn btn-default\"><b>".$ids."</b><br />";                       
                                    echo "<div class=\"badge\">".$timeleft."s</div></a></div>";
                                }
                            } else {
                                foreach ($whos as $ids) {
                                    $noone[] = $ids + 1;
                                }
                            }
                        }                           
                    }

How can I query other table using each $ids to get username and display them?