methuselah methuselah - 9 months ago 32
jQuery Question

Fetching rows from MySQL table and displaying them as JGROWL notifications

I am having problems implementing my PHP/MySQL code into a jgrowl.

If you are familiar with jgrowl you will know it delivers notifications like Growl does for OS X.

I am trying to get it read all the records from my table but at the moment it is only displaying one record as a notification and it loops through it 4 times.

Another problem is that if I have 5 rows in the table then jgrowl will only display 4 notifications are going to be viewed.

How do I get it to view all the records in the table as notifications and how do I display the total number of records (5) as notifications and account for the missing one at the moment?

<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() {};



// 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 < <?php echo $totalRows_comment; ?> ) {


echo '$.jGrowl("'.$row_comment['comment'].'",';


sticky: true,
log: function() {
console.log("Creating message " + i + "...");
beforeOpen: function() {
console.log("Rendering message " + y + "...");

} , 1000 );




Answer Source

Your problem is definitely not in fetching rows.
All these problems grows from the same root: an unclear goal. What javascript code you want to get?

You have to divide your job into 2 parts and done them separately:

  1. Apart from PHP and MySQL write your Growl or whatever code and and debug it until it gets to work. Every bit of data must be hardcoded, just like there is no PHP and mysql at all and your data is static.

  2. Once you get (1) to work, the easiest part will remain: just write a PHP/MySQL code that generates exact copy of your javascript code. Not a big deal.

That's all.
Just don't sit between 2 stools.
Hope this helps