1

I am preparing an university project: online book selling shop environment. I have a PHP page that updates few values in a table while another PHP page that runs a SELECT query to display the values of table. The problem is after the first page updates the value, the second page doesn't display the changes instantly. There is a handful amount delay before the changes take effect in display. What could possibly be the reason? And how could the same be solved?

P.S. I am using these PHP pages to implement JSON Parsing for my Android Development(using volley)

First one:

<?php

include_once("connect_seller.php");
$table= $_GET['pin'];
$orderid= $_GET['oid'];
$sellerid= $_GET['id'];
$orderstatus= $_GET['ostat'];

$query1 = "SELECT COUNT(status) FROM " . $table . "WHERE order_id='$orderid' AND status=-1";

$result = mysqli_query($conn,$query1);
$res = mysqli_fetch_assoc($result);

if($res["COUNT(status)"] > 0)
{

    $query = "UPDATE " . $table . "SET order_status='$orderstatus', status='served' , served_by='$sellerid' WHERE order_id='$orderid'";


    if(mysqli_query($conn,$query))
    {

        echo '{"maal":[{';
        echo '"message":"success"}';
        echo ']}';
    }
    else
    {
        echo '{"maal":[{';
        echo '"message":"error"}';
        echo ']}';
    }
}
else
{
    echo '{"maal":[{';
        echo '"message":"taken"}';
        echo ']}';
}
?>

Second one:

<?php
include_once("connect_seller.php");

if( isset($_GET['pin'])) {

    $table= $_GET['pin'];

    $query = "SELECT COUNT(status) FROM " . $table . "WHERE status=-1";

    $result = mysqli_query($conn,$query);
    $res = mysqli_fetch_assoc($result);

    if($res["COUNT(status)"] > 0)
    {

        $query1 = "SELECT order_id, timestamp, zip, status, order_status FROM  " . $table . "WHERE status=-1";

        $result1 = mysqli_query($conn,$query1);
        $myArray = array();

        while($row = $result1->fetch_array(MYSQLI_ASSOC)) {

            $myArray[] = $row;
        }



        echo '{"maal":';
        echo json_encode($myArray, JSON_UNESCAPED_SLASHES);
        echo "}";
        }
        else
        {
            echo 'null';
        }
}
?>
sm1979
  • 290
  • 1
  • 9
Saptak Das
  • 33
  • 7

1 Answers1

0

Your delayed reponse is maybe your cache which keep the value, try :

<?php
    header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
?>
Community
  • 1
  • 1
A-312
  • 10,203
  • 4
  • 38
  • 66
  • @SaptakDas Can you copy/paste the header of request and response (of the first and second page) ? Like this : http://stackoverflow.com/questions/4423061/view-http-headers-in-google-chrome – A-312 Dec 16 '16 at 14:25