2010-05-27 31 views
0

我在執行我的PHP/MySQL代碼到jgrowl時遇到問題。從MySQL表中獲取行並將它們顯示爲JGROWL通知

如果您熟悉jgrowl你就會知道它提供了類似的通知低吼確實爲OS X

我試圖把它從我的表讀取所有的記錄,但目前它只是顯示一個記錄作爲通知,並通過它循環4次。

另一個問題是,如果我在表中有5行,那麼jgrowl將只顯示4個通知將被查看。

如何獲取它以查看錶格中的所有記錄作爲通知,以及如何顯示記錄總數(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> 

回答

1

您的問題絕對不是在獲取行。
所有這些問題都來自同一根:一個不明確的目標。你想要得到什麼JavaScript代碼?

你有你的工作分爲兩個部分,並分別做了他們:

  1. 從PHP和MySQL

    除了寫你的低吼或任何代碼和調試,直到它開始工作。每一點數據都必須進行硬編碼,就像沒有PHP和MySQL一樣,你的數據是靜態的。

  2. 一旦你得到(1)的工作,最簡單的部分將保持:只需編寫一個PHP/MySQL代碼,生成確切副本您的JavaScript代碼。沒什麼大不了的。

就這樣。
只是不要坐在2個凳子之間。
希望這可以幫助

+0

咆哮代碼效果很好,我只是難以理解的jquery部分,因爲我不熟悉它。我需要一些幫助來做到這一點 – methuselah 2010-05-27 02:58:14

相關問題