Using jQuery Growl with PHP and MySQL

713

On my database I am planning to create a table storing messages to alert users of anything they need to do.

I am looking at using a jQuery growl like notification method but I'm confused at how I would begin building it.

The data would be added into the database using the standard MySQL insert method from a form but how would I select messages from the database to display using the jQuery growl.

Would this require the use of AJAX?

This is the JavaScript code I have so far, i was wondering how I would implement the PHP code alongside it so that I can pull out data from my tables to display as notifications:

        <script type="text/javascript"> 

    // In case you don't have firebug...
    if (!window.console || !console.firebug) {
        var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
        window.console = {};
        for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {};
    }

    (function($){

        $(document).ready(function(){

            // This specifies how many messages can be pooled out at any given time.
            // If there are more notifications raised then the pool, the others are
            // placed into queue and rendered after the other have disapeared.
            $.jGrowl.defaults.pool = 5;

            var i = 1;
            var y = 1;

            setInterval( function() {
                if ( i < 3 ) {
                    $.jGrowl("Message " + i, {
                        sticky:         true,
                        log:            function() {
                            console.log("Creating message " + i + "...");
                        },
                        beforeOpen:     function() {
                            console.log("Rendering message " + y + "...");
                            y++;
                        }
                    });
                }

                i++;
            } , 1000 );

        });
    })(jQuery);

    </script>                     
                <p>

</span>
<p>
829

Answer

Solution:

PHP is running on the server and JavaScript is running on the client.

So Yeah, you'll need AJAX.

Well, there would be other ways, but they are more work than simply setting up AJAX. Especially so since you work with jQuery which handles most of the AJAX stuff for you.

Let it call a small PHP script that fetches the Rows from the DB, outputs them in your preferred Way (XML or JSON) and exits.

The usual jQuery AJAX tutorials should cover exactly that.

If your App is Multi-User don't forget to send a UserID in the Request so PHP knows what Rows to pull.

People are also looking for solutions to the problem: recursion - php recursive list help

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.