How to output the name of their foreign key id
<p>I have a problem, I want that each id in the foreign key can output the name instead of their  id. <a href="http://i.stack.imgur.com/v9QvZ.png" rel="nofollow">Here</a> is the image.</p>

<p>Here's my code :</p>

<pre><code>&lt;table class="altrowstable" data-responsive="table" &gt;
                &lt;thead &gt;
                    &lt;tr&gt;
                        &lt;th&gt; IDno&lt;/th&gt;
                        &lt;th&gt; Lastname &lt;/th&gt;
                        &lt;th&gt; Firstname &lt;/th&gt;
                        &lt;th&gt; Department &lt;/th&gt;
                        &lt;th&gt; Program &lt;/th&gt;
                        &lt;th&gt; Action&lt;/th&gt;

                    &lt;/tr&gt;
                &lt;/thead&gt;
                &lt;tbody&gt; 
                 &lt;div style="text-align:center; line-height:50px;"&gt; 
                        &lt;?php
                        include('../connection/connect.php');
                        $YearNow=Date('Y');

                        $result = $db-&gt;prepare("SELECT * FROM student,school_year  where  user_type =3 AND student.syearid = school_year.syearid AND school_year.from_year like $YearNow ");
                        $result-&gt;execute();
                        for($i=0; $row = $result-&gt;fetch(); $i++){
                        ?&gt;
                    &lt;tr class="record"&gt;
                        &lt;td&gt;&lt;?php echo $row['idno']; ?&gt;&lt;/td&gt;
                        &lt;td&gt;&lt;?php echo $row['lastname']; ?&gt;&lt;/td&gt;
                        &lt;td&gt;&lt;?php echo $row['firstname']; ?&gt;&lt;/td&gt;
//name belong's to their id's
                            &lt;td&gt;&lt;?php echo $row['dept_id']; ?&gt;&lt;/td&gt;
                            &lt;td&gt;&lt;?php echo $row['progid']; ?&gt;&lt;/td&gt;

                    &lt;td&gt;&lt;a style="border:1px solid grey; background:grey; border-radius:10%; padding:7px 12px; color:white; text-decoration:none; " href="addcandidates.php?idno=&lt;?php echo $row['idno']; ?&gt;" &gt; Running&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
        &lt;?php
            }
        ?&gt;
            &lt;/tbody&gt;
                &lt;/table&gt;    
</code></pre>

<p>Thanks guys need a help</p>