Retrieve Data From MySQL Using PHP

Today, We want to share with you how to fetch data from database in php.In this post we will show you php code to retrieve data from mysql database and display, hear for how to get data from database in php using id we will give you demo and example for implement.In this post, we will learn about how to fetch data from database in php and display in table with an example.

how to retrieve data from database in php using mysqli

There are the Following The simple About how to fetch data from database in php and display in html table Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to fetch data from database in php and display in div, so the how to display data from database in php in table is used for this example is following below.

Also Read This πŸ‘‰   AngularJS Adding Form Fields Dynamically with PHP MySQLi

For get or retrieve or fetch data from PHP MySQL the SELECT query statement is used. I can retrieve all the members data from specific table column or all column of a table in Database.

To get selected table column data from mysql database the SQL query is

SELECT specific_column_name1,specific_column_name2, ....., ..... FROM DB_table_name;

To retrieve or get all the table column data from a table the SQL query is

SELECT * FROM DB_table_name;

In the below simple php example i retrieve the data from MySQL database.

In this example i used main 2 file for retrieve fetch data all the members

  • dbConfig.php- To connecting database.
  • retrieve.php- For retrive data from MySQL database

Step 1: connecting database


 die('Could not Connect My Sql:' .mysql_error());

Step 2: PHP retrive data from database


include_once 'dbConfig.php';
$result = mysqli_query($conn,"SELECT * FROM mymembers");
<!DOCTYPE html>
 <title> Retrive data -</title>
if (mysqli_num_rows($result) > 0) {
    <td>First Name</td>
    <td>Last Name</td>
    <td>Email id</td>
while($data = mysqli_fetch_array($result)) {
    <td><?php echo $data["profile_nm"]; ?></td>
    <td><?php echo $data["real_nm"]; ?></td>
    <td><?php echo $data["full_address"]; ?></td>
    <td><?php echo $data["email"]; ?></td>
    echo "No result found";

Step 2: Create a Custom CSS File


table {
    font-family: arial, sans-serif;
    border-collapse: collapse;
    width: 100%;

td, th {
    border: 1px solid #dddddd;
    text-align: left;
    padding: 8px;


tr:nth-child(even) {
    background-color: white;


You can also read about AngularJS, ASP.NET, VueJs, PHP.

Also Read This πŸ‘‰   Laravel 6.2 jQuery AJAX CRUD Tutorial

I hope you get an idea about how to fetch data from database in php.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.