 <p>Try this in the place of while loop:</p> <pre><code>&lt;?php $res = mysqli_query($conn,"select * from dept_manager"); echo"dept_manager"; echo "&lt;table&gt;"; while($row=mysqli_fetch_assoc($res)) { echo "&lt;tr&gt;&lt;td&gt;" . $row['emp_no'] . "&lt;/td&gt;&lt;td&gt;" . $row['dept_no'] . "&lt;/td&gt;&lt;td&gt;" . $row['from_date'] . "&lt;/td&gt;&lt;td&gt;" . $row['to_date'] . "&lt;/td&gt;&lt;/tr&gt;"; } echo "&lt;/table&gt;"; ?&gt; </code></pre>