Selecting MySQL Table Using Datatable PHP Script

Selecting MySQL Table Using Datatable PHP Script

This tutorial will show you how to select mysql table with the use of data table. Datatable is an organize presentation on database table. It is often used in websites and php program because it has an in-built function like the search and pagination.
Creating our Database

First, we’re going to create a database that contains the user data.
1. Open phpMyAdmin.
2. Click databases, create a database and name it as “datatable”.
3. After creating a database, click the SQL and paste the below code. See image below for detailed instruction.

`firstname` VARCHAR(30) NOT NULL,
`lastname` VARCHAR(30) NOT NULL,
`address` VARCHAR(150) NOT NULL,
`birthdate` DATE NOT NULL,
PRIMARY KEY (`userid`)



Inserting Data into our Database

Next, we insert data into our database. These data will show as we select our table using datatable.
1. Click our database “datatable”.
2. Click SQL and paste the below code.


INSERT INTO `user` (`firstname`, `lastname`, `address`, `birthdate`) VALUES
('neovic', 'devierte', 'silay city', '1992-06-23'),
('lee', 'ann', 'silay city', '1990-01-01'),
('dee', 'dee', 'talisay city', '1996-08-09'),
('julyn', 'divinagracia', 'bacolod city', '1992-04-09');


Creating our Connection

Next step is to create a database connection and save it as “conn.php”. This file will serve as our bridge between our page and our database. To create the file, open your HTML code editor and paste the code below after the tag.


$conn = mysqli_connect("localhost","root","","datatable");

// Check connection
if (mysqli_connect_errno())
echo "Failed to connect to MySQL: " . mysqli_connect_error();


Creating our Table

Lastly, we create our table using the datatable. We save this as “index.php”. To create the table, open your HTML code editor and paste the code below after the tag.


<!DOCTYPE html>
<html lang="en">
<title>Datatable Example PHP MySQLi</title>

<link href="bootstrap.min.css" rel="stylesheet">
<link href="dataTables.bootstrap.css" rel="stylesheet">
<link href="dataTables.responsive.css" rel="stylesheet">

<div class="mytable">
<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
$query=mysqli_query($conn,"select * from `user`");
<td><?php echo $row['userid']; ?></td>
<td><?php echo $row['firstname']; ?></td>
<td><?php echo $row['lastname']; ?></td>
<td><?php echo $row['address']; ?></td>
<td><?php echo $row['birthdate']; ?></td>
<script src="jquery.min.js"></script>
<script src="jquery.dataTables.min.js"></script>
<script src="dataTables.bootstrap.min.js"></script>
<script src="dataTables.responsive.js"></script>
<script src="bootstrap.min.js"></script>
$(document).ready(function() {
responsive: true



Read Me


Find More Selecting MySQL Table Using Datatable PHP Script

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *



Wordpress  Create Free Website (Web Builder)
Uploadfile  Upload File Website (Unlimited)
Mobilelist  Mobile Price Website (Mobilelop)
Blog  Create Blog Website (Wapfo)
Wapbuilder  Create Free Wapsite (Wapbuilder)