0

Im having a php program that will calculate the time difference and return the value in minutes.

for the message popup i use jGrowl

so what i would like to do is get the return value and if its less than 30 minutes display the jquery message.

and most importantly it should be running live. so if a user is in a page without navigating or refreshing, if the time is less than 30 minutes the popup should appear real-time.

can someone please suggest me how to use the return value to achieve the above requirement?

Below if the code that im using to calcutale the time differnce

    function time($dbtime, $currtime)
    {
        //format year-month-day hour:min:secs
        $current = strtotime($currtime);
        $indb = strtotime($dbtime);
        $minits =  round(abs($current - $indb) / 60,2);

        return $minits;
    }

currently im poping up only the messages on date

<script type="text/javascript">

        (function($){

            $(document).ready(function(){

                // jGrowl
                if ($.fn.jGrowl) {
                    // This value can be true, false or a function to be used as a callback when the closer is clciked
                            $.jGrowl.defaults.closer = function() {
                                console.log("Closing everything!", this);
                            };

                            // A callback for logging notifications.
                            $.jGrowl.defaults.log = function(e,m,o) {
                                $('#logs').append("<div><strong>#" + $(e).attr('id') + "</strong> <em>" + (new Date()).getTime() + "</em>: " + m + " (" + o.theme + ")</div>")
                            }               


                            <?php foreach ($dailies as $daily):?>
                            $.jGrowl("<?php echo $daily['calendars'][0]['Title']?>", { header: 'At <?php echo $daily['calendars'][0]['Start'];?>', sticky: true });


                            <?php endforeach;?>

                            $.jGrowl.defaults.closerTemplate = '<div>hide everything</div>';


                }

            });
        })(jQuery);

    </script>
PeeHaa
  • 71,436
  • 58
  • 190
  • 262
LiveEn
  • 3,193
  • 12
  • 59
  • 104
  • 1
    Have separate PHP page returning JSON (use ```json_encode```) and then use the response object to do whatever you want to do! – MaX Jul 24 '12 at 17:05
  • @MaX could u explain a bit further please? – LiveEn Jul 24 '12 at 17:29
  • I don't see any code there where you're checking a value and displaying a message if it meets criteria. Where are you saving the passed time and where are you checking it? It doesn't look like you call your `time` function anywhere. – MrOBrian Jul 24 '12 at 17:42
  • @MrOBrian the time function returns the minutes and is accessible through $alarm->timediffn. Actually what you are asking me is what i have asked in the question. the problem is i dont know how to use the returned value to make a real time popup. i would like to know how to do the checking in real time. – LiveEn Jul 24 '12 at 18:02

1 Answers1

0

Have a php script that takes passed parameters, in this case the two times. Write the script to return the results as JSON. This is the part I assume you already have done. If you don't have the results returning as as JSON string you can read up on JSON here.

In your webpage, make the request with javascript & ajax. Basically, when the user clicks a button, send the info asynchronously to your php script, and when the response is received display the inf to the user. You can read up on Javascript & Ajax here.

Autonomy
  • 402
  • 4
  • 13