0

I have a table name order_detail in MySQL database and I get values in it from my android app so I want to show order_id as a notification in my admin panel which is coded in HTML/PHP

Table Name: order_detail its attributes are as follow

item_id | order_id | item_name | price | quantity

I have notification icon in my admin panel I want to show order_id in it whenever someone gives order from android app and that order is stored in above-mentioned table I get notification

code for notification icon is:

 <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="label label-pill label-danger count" style="border-radius:10px;"></span> <span class="glyphicon glyphicon-envelope" style="font-size:18px;"></span></a>
Ramy M. Mousa
  • 5,727
  • 3
  • 34
  • 45
M Saad
  • 17
  • 6

1 Answers1

0

There are many many ways to do so. I'll demonstrate 2 ways one for beginner and the other is way more advanced.

1- Create a PHP function that gets user notifications from the database and call it using ajax and setInterval() js function to automatically call the server-side function every certain period of time (ex: 10 seconds) Example code:

Javascript

function getUserNotifications() {
    //Call server here and get notifications
    //Then modify notifications list in HTML.
}

//Then use the setInterval function on document ready
setInterval(getUserNotifications, 10000); //10000 = 10 seconds

2- Get to learn about WebPush and the numerous packages out there that can get real-time notifications sent from server to client. Example packages for PHP: Github: Web push php and Stackoverflow: How to use web push php library and finally a Github web push example project

Enjoy learning.

Ramy M. Mousa
  • 5,727
  • 3
  • 34
  • 45