douqipi9704 2014-03-24 01:04
浏览 17
已采纳

生成的数组值在While语句后更改

This is a weird issue I have came across and was wondering if anyone my have insight. Not sure if the mktime does not function as I am trying to get it to, or what may be going on.

Last night, things were working fine - the months being displayed were correct. Today, though, for some reason the values of my $aGMonV are changing somewhere after the foreach and before the while(row_* = mysqli_fetch_array* statements.

While the var_dump returns %2014-03% as the first month (which is correct) - the table that is generated returns %2013-09% as the first month. All the queries being ran are being run with %2013-09% and NOT starting at current month.

My code is below:

$aGMon = array();

for ($i = 0; $i < 20; $i++)
{ $aGMon[] = date('Y-m', mktime(0,0,0,date('n')-$i,1)); }

foreach ($aGMon as $aGMonK => $aGMonV)

{

$aGMonO = $aGMonV;
$aGMonV = " '%" . $aGMonV . "%' ";

$result_E = mysqli_query($con,"select kWh_AVG from UseElecM where Month LIKE " .     $aGMonV . ";");
$result_G = mysqli_query($con,"select TotalMCF from UseGas where Month LIKE " . $aGMonV     . ";");
$result_P = mysqli_query($con,"select (A.Minutes+E.Minutes_L500+E.Minutes_Free) as     Minutes, (A.Texts+E.Texts) as Texts, (A.MMS+E.MMS) as MMS, (A.MBData+E.MBData) as MBData     from UseSprintA A left outer join UseSprintE E on A.Bill = E.Bill where A.Bill     LIKE " . $aGMonV . ";");
$result_T = mysqli_query($con,"select cast((avg(Average)) as decimal (10,1)) as ATF     from CF6MCI where Date LIKE " . $aGMonV . ";");

var_dump($aGMonV);

while($row_E = mysqli_fetch_array($result_E))
while($row_G = mysqli_fetch_array($result_G))
while($row_P = mysqli_fetch_array($result_P))
while($row_T = mysqli_fetch_array($result_T))

{

echo "<td class='UUMonth'>" . ($aGMonO) . "<div class='UUMonthO'>Average temperature: "     . $row_T['ATF'] . " F</div></td>";
echo "<td>" . $row_E['kWh_AVG'] . "</td>";
echo "<td>" . $row_G['TotalMCF'] . "</td>";
echo "<td>" . $row_P['Minutes'] . "</td>";
echo "<td>" . $row_P['Texts'] . "</td>";
echo "<td>" . $row_P['MMS'] . "</td>";
echo "<td>" . $row_P['MBData'] . "</td>";
echo "</tr>";

}

}

Results of the code are as follows:

Result of code

  • 写回答

1条回答 默认 最新

  • dongyi7513 2014-03-24 01:29
    关注

    user3260912 try removing the while, try like this:

    $aGMon = array();
    
    for ($i = 0; $i < 20; $i++)
    { $aGMon[] = date('Y-m', mktime(0,0,0,date('n')-$i,1)); }
    
    foreach ($aGMon as $aGMonK => $aGMonV)
    
    {
    
    $aGMonO = $aGMonV;
    $aGMonV = " '%" . $aGMonV . "%' ";
    
    $result_E = mysqli_query($con,"select kWh_AVG from UseElecM where Month LIKE " .     $aGMonV . ";");
    $result_G = mysqli_query($con,"select TotalMCF from UseGas where Month LIKE " . $aGMonV     . ";");
    $result_P = mysqli_query($con,"select (A.Minutes+E.Minutes_L500+E.Minutes_Free) as     Minutes, (A.Texts+E.Texts) as Texts, (A.MMS+E.MMS) as MMS, (A.MBData+E.MBData) as MBData     from UseSprintA A left outer join UseSprintE E on A.Bill = E.Bill where A.Bill     LIKE " . $aGMonV . ";");
    $result_T = mysqli_query($con,"select cast((avg(Average)) as decimal (10,1)) as ATF     from CF6MCI where Date LIKE " . $aGMonV . ";");
    
    //var_dump($aGMonV);
    
    $row_E = mysqli_fetch_array($result_E);
    $row_G = mysqli_fetch_array($result_G);
    $row_P = mysqli_fetch_array($result_P);
    $row_T = mysqli_fetch_array($result_T);
    
    
    
    echo "<td class='UUMonth'>" . ($aGMonO) . "<div class='UUMonthO'>Average temperature: "     . $row_T['ATF'] . " F</div></td>";
    echo "<td>" . $row_E['kWh_AVG'] . "</td>";
    echo "<td>" . $row_G['TotalMCF'] . "</td>";
    echo "<td>" . $row_P['Minutes'] . "</td>";
    echo "<td>" . $row_P['Texts'] . "</td>";
    echo "<td>" . $row_P['MMS'] . "</td>";
    echo "<td>" . $row_P['MBData'] . "</td>";
    echo "</tr>";
    
    
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料