How to output the name in their id : I have a problem, I want that each id in the foreign key can output the name instead of their  id. [Here's the image][1]

Here's my code :

    <table class="altrowstable" data-responsive="table" >
    				<thead >
    					<tr>
    						<th> IDno</th>
    						<th> Lastname </th>
    						<th> Firstname </th>
    						<th> Department </th>
    						<th> Program </th>
    						<th> Action</th>
    	
    					</tr>
    				</thead>
    				<tbody>	
    				 <div style="text-align:center; line-height:50px;"> 
    						<?php
    						include('../connection/connect.php');
    						$YearNow=Date('Y');
    						
    						$result = $db->prepare("SELECT * FROM student,school_year  where  user_type =3 AND student.syearid = school_year.syearid AND school_year.from_year like $YearNow ");
    						$result->execute();
    						for($i=0; $row = $result->fetch(); $i++){
    						?>
    					<tr class="record">
    						<td><?php echo $row['idno']; ?></td>
    						<td><?php echo $row['lastname']; ?></td>
    						<td><?php echo $row['firstname']; ?></td>
    //name belong's to their id's
        						<td><?php echo $row['dept_id']; ?></td>
        						<td><?php echo $row['progid']; ?></td>
        					
    					<td><a style="border:1px solid grey; background:grey; border-radius:10%; padding:7px 12px; color:white; text-decoration:none; " href="addcandidates.php?idno=<?php echo $row['idno']; ?>" > Running</a></div></td>
    </tr>
    		<?php
    			}
    		?>
    			</tbody>
    				</table>	
Thanks guys need a help
  [1]: http://i.stack.imgur.com/aOWkd.png

