[英]Fetching rows from MySQL table and displaying them as JGROWL notifications
I am having problems implementing my PHP/MySQL code into a jgrowl. 我在将我的PHP / MySQL代码实现到jgrowl中时遇到问题。
If you are familiar with jgrowl you will know it delivers notifications like Growl does for OS X. 如果您熟悉jgrowl,您将知道它会像Growl一样为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. 我试图让它从我的表中读取所有记录,但目前它仅显示一条记录作为通知,并且它遍历4次。
Another problem is that if I have 5 rows in the table then jgrowl will only display 4 notifications are going to be viewed. 另一个问题是,如果我在表中有5行,那么jgrowl将仅显示4条要查看的通知。
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? 如何获取它以通知的形式查看表中的所有记录,以及如何以通知的形式显示记录总数(5)并说明当前缺少的记录?
<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 < <?php echo $totalRows_comment; ?> ) {
<?php
echo '$.jGrowl("'.$row_comment['comment'].'",';
?>
{
sticky: true,
log: function() {
console.log("Creating message " + i + "...");
},
beforeOpen: function() {
console.log("Rendering message " + y + "...");
y++;
}
});
}
i++;
} , 1000 );
});
})(jQuery);
</script>
<p>
</span>
<p>
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? 您想获得什么JavaScript代码?
You have to divide your job into 2 parts and done them separately: 您必须将工作分为两部分并分别完成:
Apart from PHP and MySQL write your Growl or whatever code and and debug it until it gets to work. 除了PHP和MySQL,还可以编写Growl或任何代码,然后对其进行调试,直到它起作用为止。 Every bit of data must be hardcoded, just like there is no PHP and mysql at all and your data is static. 数据的每一位都必须经过硬编码,就像根本没有PHP和mysql一样,您的数据是静态的。
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. 一旦您开始工作(1),最简单的部分将仍然存在:只需编写一个PHP / MySQL代码即可生成您的JavaScript代码的精确副本 。 Not a big deal. 没有大碍。
That's all. 就这样。
Just don't sit between 2 stools. 只是不要坐在两个凳子之间。
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.