session_start();
require('db/connect.php');
if($_SESSION['per_id']<=2)
{
$sql_orders = "select * from orders where order_status = 1";
$sql_request = "select * from stock_request where status = 1 order by date asc";
}
else
{
$sql_orders = "select * from orders where order_status = 1 and branch_id = '".$_SESSION['branch_id']."'";
$sql_request = "select * from stock_request where status <= 1 and branch_id = '".$_SESSION['branch_id']."' order by date asc";
}
$result_orders = $conn->query($sql_orders);
$num_rows_orders = $result_orders->num_rows;
$result_request = $conn->query($sql_request);
$num_rows_request = $result_request->num_rows;
$data = array();
if($num_rows_orders or $num_rows_request){
$data['orders'] = array($num_rows_orders);
$data['request'] = array($num_rows_request);
echo json_encode($data);
}
session_start();
require('head.php');
if($_SESSION['per_id']<=2)
{
$sql_orders = "select * from orders where order_status = 1";
$sql_request = "select * from stock_request where status = 1 order by date asc";
}
else
{
$sql_orders = "select * from orders where order_status = 1 and branch_id = '".$_SESSION['branch_id']."'";
$sql_request = "select * from stock_request where status <= 1 and branch_id = '".$_SESSION['branch_id']."' order by date asc";
}
$result_orders = $conn->query($sql_orders);
$num_rows_orders = $result_orders->num_rows;
$result_request = $conn->query($sql_request);
$num_rows_request = $result_request->num_rows;
if($num_rows_orders or $num_rows_request){
echo json_encode(array(
'orders' => $num_rows_orders,
'request' => $num_rows_request
));
}
<?php
session_start();
require('head.php');
if($_SESSION['per_id']<=2)
{
$sql_orders = "select * from orders where order_status = 1";
$sql_request = "select * from stock_request where status = 1 order by date asc";
}
else
{
$sql_orders = "select * from orders where order_status = 1 and branch_id = '".$_SESSION['branch_id']."'";
$sql_request = "select * from stock_request where status <= 1 and branch_id = '".$_SESSION['branch_id']."' order by date asc";
}
$result_orders = $conn->query($sql_orders);
$num_rows_orders = $result_orders->num_rows;
$result_request = $conn->query($sql_request);
$num_rows_request = $result_request->num_rows;
$data = array(
'c_orders' => $num_rows_orders,
'c_request' => $num_rows_request
);
echo json_encode($data);
?>
อ๋อ ผมผิดเองพอดีเปลี่ยนชื่อตัวแปร แล้วลืมแก้ if
ขออนุญาติอัพเดตอีกทีครับ increase.php
<?php
session_start();
require('head.php');
if($_SESSION['per_id']<=2)
{
$sql_orders = "select * from orders where order_status = 1";
$sql_request = "select * from stock_request where status = 1 order by date asc";
}
else
{
$sql_orders = "select * from orders where order_status = 1 and branch_id = '".$_SESSION['branch_id']."'";
$sql_request = "select * from stock_request where status <= 1 and branch_id = '".$_SESSION['branch_id']."' order by date asc";
}
$result_orders = $conn->query($sql_orders);
$num_rows_orders = $result_orders->num_rows;
$result_request = $conn->query($sql_request);
$num_rows_request = $result_request->num_rows;
$data = array(
'c_orders' => $num_rows_orders,
'c_request' => $num_rows_request
);
echo json_encode($data);
?>
ข้อมูลที่ได้
orders:1 และ request:0 ถูกต้องตาม DB notification.js
$(document).ready(function() {
increaseNotify();
setInterval(increaseNotify, 10000);
function increaseNotify(){
$.ajax({
url: "increase.php",
type: "POST",
success: function(count) {
if(count.c_orders > 0){
$('.orders').html(count.c_orders);
sound_orders();
}
if(count.c_request > 0){
$('.request').html(count.c_request);
}
}
});
}
function sound_orders(){
var audio = new Audio('./sound/orders.mp3');
audio.play();
}
});