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 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大