douyin7829 2014-05-10 11:49
浏览 31

使用数组值PHP MYSQL处理foreach或for循环

Output Array (The variable name is $r)

    Array
    (
    [Jan-14] => 7588793.52
    [Feb-14] => 9944970.87
    [Mar-14] => 8567790.20
    [Apr-14] => 
    [May-14] => 
    [Jun-14] => 
    [Jul-14] => 
    [Aug-14] => 
    [Sep-14] => 
    [Oct-14] => 
    [Nov-14] => 
    [Dec-14] => 
    )

What I have done so far is..

   while($r = mysql_fetch_assoc($query)) {
    $series1['data'][] = $r['Jan-14'];
    $series2['data'][] = $r['Feb-14'];
    .... it will go till Dec-14.......
    array_push($result,$series1);
    array_push($result,$series2);
    .... it will go till Dec-14.......
}

Expected Output:

The code should look something like this this (dynamic)

  while($r = mysql_fetch_assoc($query)) {

        for($i=1;$i<=count($r);$i++){

        $series.$i['data'][] =  ??????????
        array_push($result,$series.$i);
        ..................

        }

}

Help me out. Don't talk about the db structure or normalization. The db was given by my client.

Thanks, Kimz

  • 写回答

1条回答 默认 最新

  • doumu8911 2014-05-10 11:53
    关注

    Do you mean like this?

    $result = array();
    foreach($r as $month => $value) {
        $result[] = array('data' => array($value));
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch