Hello friends yesterday i was helping some guy at a website. He want to know that how to Retrieve Data from Database in PHP Display in Table Format. So this tutorial is all about getting the values from database and showing it over the website in table format. This is very simple and easy tutorial. Lets suppose we have a table name employee which consists of 5 columns.
- EmployeeName
- DateJoining
- DOB
- Mobile
- Designation
Now we need this whole data in a table or we need a specific row. For getting the whole data we have to use the Select query. “Select * from employee” By using this query statement we will get all the data and the main part is we have to show it to our page using the PHP and HTML. Retrieve Data from Database in PHP and Display in Table Format We will create the table directly from the PHP and show it over the page We will take the EmployeeName.
public function showTable(){ $query="Select * from employee"; $result=mysqli_query($con,$query) $count=mysqli_num_rows($result); if(!$count < 1) { $alert="<table>"; While($row=mysqli_fetch_array($result)) { $alert.="<tr><td>$row[EmployeeName]</td></tr>"; } $alert.="</table>"; return $alert; } } else { return "There is no any data in table"; }
Now if you call the showTable() function it will print the table with the employee name.
Hope you understand the tutorial and if you have any issue please let me know. Leave you comment or question we will b happy to help you. So this tutorial is all about the Retrieve Data from Database in PHP Display in Table Format.
~~~~ Happy Coding ~~~~
No Comments