How To Display Data From MySQL Table Using PHP
![]() |
| how to fetch data from database in php and display |
if you are beginners in php and mysql and if you don't know how to fetch and display data from mysql database please follow the below example...
Overview and Requirements:
In This Tutorials We Will Learn Displaying Data Form MySQL Database Using PHP.
It's Very Easy and Simple.
You need to create 2 php files.
1. connect.php
2. display.php
![]() |
| Displaying Data Form MySQL DataBase Using PHP |
MySQL Database Structure and Overview:
![]() |
| Displaying Data Form MySQL DataBase Using PHP Database Structure |
Database Name: tutorial
Table Name : test
SQL to create table for test
CREATE TABLE IF NOT EXISTS 'test' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'name' varchar(150) NOT NULL,
'email' varchar(150) NOT NULL,
PRIMARY KEY ('id')
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
Dumping some data for table test
INSERT INTO `test` (`id`, `name`, `email`) VALUES (NULL, 'ANJANBD', 'Anjankumardhali6@gmail.com'), (NULL, 'Krishna', 'krishna@mail.com'), (NULL, 'Rupam Mondal', 'RupomMondal@gmail.com'), (NULL, 'ANJAN', 'KumarANjan@gmail.com'), (NULL, 'Biswas Shiuli', 'ShiuliBiswas@gmail.com'), (NULL, 'Hrithik', 'Hrithik@gmail.com'), (NULL, 'Modhu Bonik', 'Modhu360@gmail.com'), (NULL, 'Rupam Mondal Joy', 'RupomMondal@gmail.com'), (NULL, 'Rupa', 'Rupa@hotmail.com'), (NULL, 'ANJAN', 'Kumar@gmail.com');connect.php
You have to create connect.php file to established connection between database and server..
<?php
$host="localhost"; //Host Name
$username="root"; //MySQL UserName
$password=""; //MySQL PassWord
$dbname="tutorial"; //Database Name
//Create Connection
$conn=new mysqli($host,$username,$password,$dbname);
if($conn->connect_error){
echo("Connection Failed:".$conn->connect_error);
}
?>
display.phpNow you have to create display.php file to fetch all data from test table and display..
![]() |
| Displaying Data Form MySQL DataBase Using PHP |
<!DOCTYPE html>
<html>
<head>
<title>PHP MySQL Delete Data from Table</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
</tr>
<?php
include("connect.php");
$result=mysqli_query($conn,"SELECT*FROM test"); //Selecting Data From "test" Table to Display
while($row=$result->fetch_array()){?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['email'];?></td>
</tr>
<?php } ?>
</table>
</body>
</html>
style.css
Now you have to create style.css file to design table...
table th, td{
border: 1px solid green;
text-align:left;
}
th,td{
padding:7px;
}
table{
border-collapse:collapse;
width:50%;
}
th{
padding:10px;
background:lightgreen;
font-size:18px;
font-weight:bold;
}
tr:nth-child(odd){background:#808080}
}
If You Like This Article Please Like and Share with Your Friends.
Don't Forget to Ask comments.Thank You.





No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.