php循环自动增量变量

时间:2015-03-10 16:21:01

标签: php loops

我在php中有一个循环,工作正常,我已经

$c=0;
$d=1;
while($c <=23){
    $sql = "SELECT SUM(amperagem) AS soma FROM tomada WHERE HOUR(data) >= '$c'     AND HOUR(data) < '$d' AND YEAR(data)='$ano' AND MONTH(data)='$mes' AND     DAY(data)='$diaOntem'" ;
    $retval = mysql_query( $sql, $conn );

    $row = mysql_fetch_array($retval, MYSQL_BOTH);
    $amper= $row['soma'];        

    // on the end off loop I have
    $d++;// that variable increment just one time
    $c++; //that variable autoincrement fine

}

所以问题是变量“d”增加一次。

有什么问题?

在里面我有23个ifs那样

if  ($c=0){
$calcAmperagemHora00=$amper;//soma as medições de consumo
}
  if  ($c=1){
$calcAmperagemHora01=$amper;//soma as medições de consumo
}

1 个答案:

答案 0 :(得分:0)

问题已解决,将=更改为==

if  ($c==0){
}

if  ($c==1){
}