php - 计算while循环中的总num行数

oli*_*rbj 1 php while-loop

我有这段代码:

  $i=0;
      $start_date = date("Y/m/d");
      $end_date = date('Y/m/d', strtotime($start_date . " -7 days"));



      while($days7=mysql_fetch_assoc($q)): 
          $next_date = strtotime($i--." days", strtotime($start_date));
          $date = date("Y/m/d",$next_date); 
      #Let's get the latest click combined from the latest 7 days
          $combined7=mysql_query("SELECT sum(value) FROM `xeon_stats_clicks` WHERE user='".$userdata['username']."' AND typ='4' AND data='$date' ORDER BY data DESC LIMIT 8") or die(mysql_error());              


      print mysql_num_rows($combined7);

      endwhile;  
Run Code Online (Sandbox Code Playgroud)

我需要看看有多少行$combined7.目前,我正在使用,print mysql_num_rows($combined7);但只打印出:1 1 1 1 1(每行的数字'1')

我如何计算总数?

(PS $我必须设为0)

q0r*_*0re 14

简单:

$counter = 0;
while(..) {
      $counter++; // or $counter = $counter + 1;
}

echo $counter;
Run Code Online (Sandbox Code Playgroud)

在循环外定义变量.