GamerX802
Data Lake Architect
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
500 XP
In this tutorial we will create a Merge Two Table using MySQLi. This code will merge the two existing table in the MySQLi server when user click the merge button. The code use a MySQLi SELECT() function and add a LEFT JOIN parameter to merge the the two existing table into one that has a same key in both. This is a user-friendly kind of program feel free user it in your program.
We will be using PHP as a scripting language that manage a database server to handle a bulk of data per transaction. It describe as an advance technology that manage both server and control-block of your machine.
Getting Started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.
And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.
Creating Database
Open your database web server then create a database name in it db_merge, after that click Import then locate the database file inside the folder of the application then click ok.
Creating the database connection
Open your any kind of text editor(notepad++, etc..). Then just copy/paste the code below then name it conn.php.
Creating The Interface
This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.
Creating the Main Function
This code contains the main function of the application. This code will merge the two table when the button is clicked. To make this just copy and write these block of codes below inside the text editor, then save it as merge.php.
There you have it we successfully created Merge Two Table using MySQLi. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Download
We will be using PHP as a scripting language that manage a database server to handle a bulk of data per transaction. It describe as an advance technology that manage both server and control-block of your machine.
Getting Started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.
And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.
Creating Database
Open your database web server then create a database name in it db_merge, after that click Import then locate the database file inside the folder of the application then click ok.

Creating the database connection
Open your any kind of text editor(notepad++, etc..). Then just copy/paste the code below then name it conn.php.
- <?php
- $conn
=
mysqli_connect
(
"localhost"
,
"root"
,
""
,
"db_merge"
)
;
- if
(
!
$conn
)
{
- die
(
mysqli_error
(
)
)
;
- }
- ?>
Creating The Interface
This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.
- <?php
require
'conn.php'
?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
- </div>
- </nav>
- <div class="col-md-3"></div>
- <div class="col-md-6 well">
- <h3 class="text-primary">PHP - Merge Two Table Using MySQLi</h3>
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="col-md-6">
- <center><h4>Owner</h4></center>
- <table class="table table-bordered">
- <thead class="alert-info">
- <tr>
- <th>ID</th>
- <th>Name</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $query
=
mysqli_query
(
$conn
,
"SELECT * FROM `owner`"
)
or die
(
mysqli_error
(
)
)
;
- while
(
$fetch
=
mysqli_fetch_array
(
$query
)
)
{
- ?>
- <tr>
- <td><?php
echo
$fetch
[
'owner_id'
]
?>
</td>
- <td><?php
echo
$fetch
[
'owner_name'
]
?>
</td>
- </tr>
- <?php
- }
- ?>
- </tbody>
- </table>
- <center><h4>Car</h4></center>
- <table class="table table-bordered">
- <thead class="alert-info">
- <tr>
- <th>ID</th>
- <th>Name</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $query
=
mysqli_query
(
$conn
,
"SELECT * FROM `car`"
)
or die
(
mysqli_error
(
)
)
;
- while
(
$fetch
=
mysqli_fetch_array
(
$query
)
)
{
- ?>
- <tr>
- <td><?php
echo
$fetch
[
'car_id'
]
?>
</td>
- <td><?php
echo
$fetch
[
'car_name'
]
?>
</td>
- </tr>
- <?php
- }
- ?>
- </tbody>
- </table>
- </div>
- <div class="col-md-6">
- <form method="POST" action="">
- <center><button class="btn btn-primary" name="submit">Merge Table</button></center>
- </form>
- <br />
- <?php
include
'merge.php'
?>
- </div>
- </div>
- </body>
- </html>
Creating the Main Function
This code contains the main function of the application. This code will merge the two table when the button is clicked. To make this just copy and write these block of codes below inside the text editor, then save it as merge.php.
- <?php
- if
(
ISSET
(
$_POST
[
'submit'
]
)
)
{
- ?>
- <table class="table table-bordered">
- <thead class="alert-info">
- <tr>
- <th>ID</th>
- <th>Owner Name</th>
- <th>Car</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $query
=
mysqli_query
(
$conn
,
"SELECT * FROM `owner` LEFT JOIN `car` ON owner.car_id = car.car_id"
)
or die
(
mysqli_error
(
)
)
;
- while
(
$fetch
=
mysqli_fetch_array
(
$query
)
)
{
- ?>
- <tr>
- <td><?php
echo
$fetch
[
'owner_id'
]
?>
</td>
- <td><?php
echo
$fetch
[
'owner_name'
]
?>
</td>
- <td><?php
echo
$fetch
[
'car_name'
]
?>
</td>
- </tr>
- <?php
- }
- ?>
- </tbody>
- </table>
- <?php
- }
- ?>
There you have it we successfully created Merge Two Table using MySQLi. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Download
You must upgrade your account or reply in the thread to view hidden text.