Sensation Energy


F 7 & GRID Multi PHP Mysql

Documentation - Multi home

Introduction

F 7 & GRID Multi with PHP Mysql is multi-functional CRUD. F7 Multi which helps you understand certain more complex functionalities. Of course everything is connected to the MySql database.

F 7 & GRID Multi have many functionalities such as:

  • Clone table
  • Join & Union
  • Change status
  • Multi tag

I will also show you a tutorial for Privilege & Role here.

Database


CREATE TABLE `accounts` (
`id` int(20) NOT NULL,
`firstname` varchar(200) NOT NULL,
`lastname` varchar(200) NOT NULL,
`email` varchar(200) NOT NULL,
`password` varchar(200) NOT NULL,
`enabled` int(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `accounts2` (
`id` int(20) NOT NULL,
`firstname` varchar(200) NOT NULL,
`lastname` varchar(200) NOT NULL,
`email` varchar(200) NOT NULL,
`password` varchar(200) NOT NULL,
`enabled` int(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `adress` (
`ip_id` int(20) NOT NULL,
`name` varchar(200) NOT NULL,
`ipaddress` varchar(200) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `categories` (
`cat_id` int(5) NOT NULL,
`cat_name` varchar(20) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `check_button` (
`check` varchar(100) NOT NULL,
`id` int(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `developers` (
`id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`skills` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `radio_button` (
`id` int(20) NOT NULL,
`radio` varchar(200) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `products` (
`product_id` int(5) NOT NULL,
`product_name` varchar(30) NOT NULL,
`cat_id` int(5) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `users` (
`id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`check` varchar(255) NOT NULL,
`role` varchar(100) NOT NULL,
`date` varchar(100) NOT NULL,
`product` varchar(200) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
ALTER TABLE `accounts`
ADD PRIMARY KEY (`id`);
ALTER TABLE `accounts2`
ADD PRIMARY KEY (`id`);
ALTER TABLE `adress`
ADD PRIMARY KEY (`ip_id`);
ALTER TABLE `categories`
ADD PRIMARY KEY (`cat_id`);
ALTER TABLE `check_button`
ADD PRIMARY KEY (`id`);
ALTER TABLE `developers`
ADD PRIMARY KEY (`id`);
ALTER TABLE `radio_button`
ADD PRIMARY KEY (`id`);
ALTER TABLE `products`
ADD PRIMARY KEY (`product_id`);
ALTER TABLE `users`
ADD PRIMARY KEY (`id`);
ALTER TABLE `accounts`
MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=14;
ALTER TABLE `accounts2`
MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
ALTER TABLE `adress`
MODIFY `ip_id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
ALTER TABLE `categories`
MODIFY `cat_id` int(5) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
ALTER TABLE `check_button`
MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
ALTER TABLE `developers`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
ALTER TABLE `radio_button`
MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
ALTER TABLE `products`
MODIFY `product_id` int(5) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
ALTER TABLE `users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

Connect (conn.php)


<?php
$server = "localhost";
$user = "root";
$password = "root";
$base = "f7_21";
$con = mysqli_connect($server, $user, $password, $base);
?>

Clone table

Clone table is are the values from the table that are in one table and then by copying to another with the same fields from the table you get a clone of the table.

Copy

Copy form


<form action="copy.php" method="post" enctype="multipart/form-data">
<div class="btn-group">
<div align="center">
<input type="submit" name="copy" value="Copy values from table 'accounts' to table 'accounts2'">
</div>

Copy function (copy.php)


<?php
require 'conn.php';
if (isset($_POST['copy'])) {
$sql = "INSERT INTO accounts2 (select * from accounts)";
$vlada = mysqli_query($con, $sql);
echo "<script>alert('Copy!')</script>";
}
?>

Delete

Delete form


<form action="dele.php" method="post" enctype="multipart/form-data">
<div class="btn-group">
<div align="center">
<input type="submit" name="dele" value="Delete values form table 'accounts2'">
</div>
</div>
</form>

Delete function (dele.php)


<?php
require 'conn.php';
if (isset($_POST['dele'])) {
$delete_post = "DELETE from accounts2";
$run_delete = mysqli_query( $con, $delete_post );
if ( $run_delete ) {
echo "<script>alert('Delete!')</script>";
}
}
?>

Original & clon table

Original table


<table>
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Password</th>
</tr>
</thead>
<tbody>
<?php
$sql="SELECT * FROM accounts";
$result = mysqli_query($konekcija, $sql);
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['firstname']; ?></td>
<td><?php echo $row['lastname']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['password']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>

Clon table


<table>
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Password</th>
</tr>
</thead>
<tbody>
<?php
$sql="SELECT * FROM accounts";
$result = mysqli_query($konekcija, $sql);
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['firstname']; ?></td>
<td><?php echo $row['lastname']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['password']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>

Change status click

Change status click is used so that users can immediately change the status in the table with one click of a button. Also when you add a value to the table on the form itself you can give it a status. In my example the status is 0 or 1.

Tabele where Change status on click button


<table>
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Password</th>
<th>Statues</th>
<th>0</th>
<th>1</th>
</tr>
</thead>
<tbody>
<?php
$sql="SELECT * FROM accounts";
$result = mysqli_query($konekcija, $sql);
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['firstname']; ?></td>
<td><?php echo $row['lastname']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['password']; ?></td>
<td><?php echo $row['enabled']; ?></td>
<td><a href="javascript:void(0)" onClick="updateId('<?php echo $row['id']; ?>')" ><button class="btn-10" onClick="refresh(this)" >1</button></a></td>
<td><a href="javascript:void(0)" onClick="uId('<?php echo $row['id']; ?>')"><button class="btn-9" onClick="refresh(this)" >0</button></a></td>
</tr>
<?php } ?>
</tbody>
</table>

Add value with status

Add form


<form action="add.php" method="post">
<div class="form-group">
<label for="title">First name</label>
<input type="text" id="title" class="form-input" name="firstname" >
</div>
<div class="form-group">
<label for="thread_title">Last name</label>
<input type="text" id="thread_title" class="form-input" name="lastname" >
</div>
<div class="form-group">
<label for="thread_title">Email</label>
<input type="text" id="thread_title" class="form-input" name="email" >
</div>
<div class="form-group">
<label for="thread_title">Password</label>
<input type="text" id="thread_title" class="form-input" name="password" >
</div>
<div class="form-group">
<label for="enabled"><h2>Enabled</h2></label>
<select  name="enabled" id="enabled" class="form-input">
<option value='1'>1</option>;
<option value='0'>0</option>;
</select>
</div>
<div class="btn-group">
<button type="submit" name="publish">Publish </button>
</div>
</form>

Add function (add.php)


lt;?php
require 'conn.php';
if (isset($_POST['publish'])) {
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$password = $_POST['password'];
$enabled = $_POST['enabled'];
$sql = "INSERT INTO accounts (enabled, password, email, lastname, firstname) VALUES('{$enabled}','{$password}','{$email}','{$lastname}', '{$firstname}')";
if (mysqli_query($con, $sql)){
echo "<script>window.history.back();</script>";
} else {
echo "Eror";
}
}
?>

IP adress

IP adress is used to enter the user's IP address and shows the IP address in the table. When you have an application where you need the user's IP address, it is entered automatically in a simple way. you can also combine it with a selection.

IP table


<table>
<thead>
<tr>
<th>Ip id</th>
<th>Name</th>
<th>IP adress</a></th>
</tr>
</thead>
<tbody>
<?php
include "conn.php";
$sql = "SELECT * FROM adress";
$result = mysqli_query($con, $sql);
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['ip_id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><a href="t_ip.php?ipaddress=<?php echo $row['ipaddress']; ?>"><?php echo $row['ipaddress']; ?></a></td>
</tr>
<?php } ?>
</tbody>
</table>

Add IP adress

IP form


<form action="u_ip.php" method="post" name="form1">
<div class="form-group">
<label for="title">Name</label>
<input class="form-input" type="text" name="name">
</div>
<div class="form-group">
<input type="submit" name="add" value="Add">
</div>
</form>

IP add function (u_ip.php)


<?php
require 'conn.php';
if(isset($_POST['add'])){
$name = $_POST['name'];
$ipaddress = $_SERVER['REMOTE_ADDR'];
$sql = "INSERT INTO adress(name,ipaddress) VALUES('$name', '$ipaddress')";
if (mysqli_query($con, $sql)){
echo "<script>window.history.go(-2);</script>";
} else {
echo "Eror";
}
}
?>

Join

Join allows you to merge two tables. There are Outer Left connections only with the left side Outer Right Join connection only with the right side Inner Join is a connection via ID and Without Join, only where condition classic here condition with connection via ID.

Example Tables

Category


<table>
<thead>
<tr>
<th>Category id</th>
<th>Category name</th>
</tr>
</thead>
<tbody>
<?php
include "conn.php";
$sql="SELECT * FROM categories";
$result = mysqli_query($con, $sql);
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['cat_id']; ?></td>
<td><?php echo $row['cat_name']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>

Product


<table>
<thead>
<tr>
<th>Product id</th>
<th>Product name</th>
<th>Category id</th>
</tr>
</thead>
<tbody>
<?php
include "conn.php";
$sql="SELECT * FROM products";
$result = mysqli_query($con, $sql);
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['product_id']; ?></td>
<td><?php echo $row['product_name']; ?></td>
<td><?php echo $row['cat_id']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>

Outer Left or Right Join

Outer Left Join


<table>
<thead>
<tr>
<th>Product id</th>
<th>Product name</th>
<th>Category name</a></th>
</tr>
</thead>
<tbody>
<?php
include "conn.php";
$sql="SELECT c.cat_name , p.product_name , p.product_id FROM categories c LEFT OUTER JOIN products p ON c.cat_id=p.cat_id";
$result = mysqli_query($con, $sql);
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['product_id']; ?></td>
<td><?php echo $row['product_name']; ?></td>
<td><?php echo $row['cat_name']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>

Outer Right Join


<table>
<thead>
<tr>
<th>Product id</th>
<th>Product name</th>
<th>Category name</a></th>
</tr>
</thead>
<tbody>
<?php
include "conn.php";
$sql = "SELECT c.cat_name , p.product_name , p.product_id FROM categories c RIGHT OUTER JOIN products p ON c.cat_id=p.cat_id";
$result = mysqli_query($cona, $sql);
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['product_id']; ?></td>
<td><?php echo $row['product_name']; ?></td>
<td><?php echo $row['cat_name']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>

With and without JOIN

Inner Join


<table>
<thead>
<tr>
<th>Product id</th>
<th>Product name</th>
<th>Category id</th>
<th>Category name</th>
</tr>
</thead>
<tbody>
<?php
include "conn.php";
$sql="SELECT c.* , p.* FROM categories c INNER JOIN products p ON c.cat_id=p.cat_id";
$result = mysqli_query($con, $sql);
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['product_id']; ?></td>
<td><?php echo $row['product_name']; ?></td>
<td><?php echo $row['cat_id']; ?></td>
<td><?php echo $row['cat_name']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>

Without Join, only where condition


<table>
<thead>
<tr>
<th>Product id</th>
<th>Product Name</th>
<th>Category name</a></th>
</tr>
</thead>
<tbody>
<?php
include "conn.php";
$sql = "SELECT c.* , p.* FROM categories c,products p WHERE c.cat_id=p.cat_id";
$result = mysqli_query($con, $sql);
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['product_id']; ?></td>
<td><?php echo $row['product_name']; ?></td>
<td><?php echo $row['cat_name']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>

Content


Documentation





Answer the following question:

You must be logged in


Advertising