1

I am doing a restaurant aplication using php, mysql and js but I have a little problem.

When a client order somthing (using a tablet) I need a notification appears in another terminal but using the "easy way".

table orders:

id  |   id_place   |  id_meal   |   id_waiter  |   status
1   |   3          |  20        |   4          |   0
2   |   4          |  17        |   4          |   0
3   |   2          |  13        |   2          |   0 
4   |   1          |  13        |   5          |   1  <-- All these are ordes 

I am thinking to do update.php:

$que = mysql_query("SELECT id, id_waiter, status FROM ordes WHERE status = 0");
$notifi = mysql_fetch_array($que);

And I have all the orders in a standby state (status = 0) and Now I can show the results counting the rows for each waiter:

Waiter2 [1]   //waiter2 has 1 notification
Waiter4 [2]   //waiter4 has 2 notifications

But these results have to be constantly updated every 5 or 10 sec. How can I do that? I dont want to use jnode, sockets or semething like that.

3 Answers 3

3

Use the method setTimeout() to call a function every X seconds that will refresh the list of orders in standby More info here : https://developer.mozilla.org/en-US/docs/DOM/window.setTimeout

If you don't want to reload the whole page you will have to use AJAX More info here : https://developer.mozilla.org/en/docs/AJAX

Sign up to request clarification or add additional context in comments.

Comments

1

In a PHP page you could use a while loop and sleep at the bottom:

<?php

while (someCondition) {
    //Get Data and show.
    sleep(5);
}

?>

You can write something in to set someCondition to false to stop the process when you need to as well.

Comments

1

use ajax. in this case i used mootools.

var that = this;
var req = new Request.HTML({
        method: that.ajax.method,
        url: that.ajax.url,
        data: {'action' : 'update', 'waiterID': x},
        onRequest: function(){ /* do something */},
        onComplete: function(){ /* do something */}
        }).send();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.