Notification System in PHP & MySql like facebook

Notification System in PHP & MySql like facebook:-
In this tutorial I am going to share a complete php mysql code for creating simple PHP and Mysql Notification System. you’ll display realtime notification alert to your visitors or users. you can simply make a notification bell on the top corner which will display all the related notification alert to user and they will be always get alerted for every new notification.

SQL

First of all create a simple database table which will store all the notification alerts.

-- phpMyAdmin SQL Dump
-- version 4.7.4
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Feb 11, 2018 at 03:07 AM
-- Server version: 10.1.30-MariaDB
-- PHP Version: 7.2.1

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `notificationsystem`
--

-- --------------------------------------------------------

--
-- Table structure for table `notifications`
--

CREATE TABLE `notifications` (
  `id` int(11) NOT NULL,
  `name` text NOT NULL,
  `type` text NOT NULL,
  `message` text NOT NULL,
  `status` text NOT NULL,
  `date` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `notifications`
--

INSERT INTO `notifications` (`id`, `name`, `type`, `message`, `status`, `date`) VALUES
(10, '', 'comment', 'Hi crush', 'read', '2018-02-09 00:21:21'),
(11, 'Irene', 'like', '', 'read', '2018-02-09 00:21:34'),
(12, 'Joe', 'like', '', 'unread', '2018-02-09 00:22:25');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `notifications`
--
ALTER TABLE `notifications`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `notifications`
--
ALTER TABLE `notifications`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


function.php

create function.php file add some common variables and methods which requited to build this notification alert project.

query($query);
        return $stmt->fetchAll();
    }
    function performQuery($query){
        $con = new PDO(DBINFO, DBUSER, DBPASS);
        $stmt = $con->prepare($query);
        if($stmt->execute()){
            return true;
        }else{
            return false;
        }
    }
?>

index.php

This is the landing page you can see list or recent notification on the top of the page and whenever you click on “view all” then a separate page will open with al the notification list so far you received.

?php
    include("functions.php");
?>


  
    
    
    
    
    

    Notification System in PHP and MySql

   

  

  

    

    

Bootstrap starter template

Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.

view.php

It’ll display list of all the notification.

Notifications

0){ foreach(fetchAll($query) as $i){ if($i['type']=='like'){ echo ucfirst($i['name'])." liked your post.
".$i['date']; }else{ echo "Some commented on your post.
".$i['message']; } } } ?>
Back

See live demo and download source code.

DOWNLOAD

This awesome script developed by labajojj, Visit their official github repository for more information and follow for future updates.

Don’t forget to Subscribe My Public Notebook for more useful free scripts, tutorials and articles.

Posted in PHP

#1 Best Web Hosting 🚀

We Recommend Hostinger

Use Code: ASKROHIT20

Hostinger is among the top 3 hosting providers. This website is also hosted on Hostinger. Enjoy ultra-fast speed, 99.9% uptime, and beginner-friendly pricing.

🔥 Get 82% OFF Now