title: very slow to show result
body: <p>I have a Windows7 system with Wamp 2.4 running this simple php code</p>
  
  <pre><code>for ($year = 2004; $year &lt;= 2015; $year++){
      for ($month = 1; $month &lt;=12; $month++){
          mysql_connect("$host", "$username", "$password")or die("cannot connect");
          mysql_select_db("$db_name")or die("cannot select DB");
          $result = mysql_query("SELECT sum(Weight) FROM Lab WHERE YEAR(date)=$year  AND MONTH(date)= $month") or die(mysql_error());
  
          while ($rows = mysql_fetch_array($result)) {
              $weight = $rows['sum(Weight)'];
              ${'mes'.$month}=$weight;
              $weight3=$weight+$weight3;
              $weight=0;
          }
      }
  
      Echo $year, " Total - ", $weight3, "&lt;br&gt;";
      Echo $mes1, ", ", $mes2, ", ", $mes3, ", ", $mes4, ", ", $mes5, ", ", $mes6, ", ", $mes7, ", ", $mes8, ", ", $mes9, ", ", $mes10, ", ", $mes11, ", ", $mes12, "&lt;br&gt;";
      $weight3=0;
  }
  </code></pre>
  
  <p>My database is about 400000 rows and for some reason it takes about 40 seconds to shows any result. If I do the same query (year by year) in mysql it takes less than a second.</p>
  
  <p>Is there anything wrong with my code that slowsdown the query? or is this a Wamp related problem?</p>
  
  <p>Thanks for any help!</p>
  
  <p>Final code </p>
  
  <pre><code>mysql_connect("$host", "$username", "$password")or die("cannot connect");
  mysql_select_db("$db_name")or die("cannot select DB");
  $result = mysql_query("SELECT year(date), month(date), sum(Weight)
  FROM Lab
  WHERE date BETWEEN '2004-01-01' AND '2015-12-31'
  GROUP BY year(date), month(date)");
     while ($rows = mysql_fetch_array($result)) {
         echo $rows ['year(date)']," ", $rows ['month(date)']," ",$rows['sum(Weight)'];
         Echo "&lt;br&gt;";
     } 
  </code></pre>