dongxiangshen7916 2013-11-23 15:03
浏览 63
已采纳

在php中向多维数组添加数据时出错

I want to read data from a data base, and put it in multi-dimensional array. I don't know number of rows that will come from data base, and when i try to add new row to the multi-dimensional array i have the following error

Warning: array_push() [function.array-push]: First argument should be an array in C:\AppServ\www\web\commands\changeservice.php on line 101

and this is the code i have

function preparenewservices()
    {

                $managername = $_SESSION['managername'];

                $sqls = "select s.*,m.* from rm_allowedmanagers m inner join rm_services s on s.srvid = m.srvid where m.managername = '$managername' ";


                $sql = mysql_query($sqls);


                 $newservices =  array();


                    while($row = mysql_fetch_array($sql))
                  {
                        $nsrvid = $row['srvid'];
                        $nsrvname = $row['srvname'];                        
                        $nunitprice = $row['unitprice'];
                        $nunitpricetax = $row['unitpricetax'];

                        $ntotal = $nunitprice + $nunitpricetax;

                        $newservice = array($nsrvid, $nsrvname , $ntotal); 

                        array_push ($newservices[count($newservices)], $newservice);

               }

    }
  • 写回答

4条回答 默认 最新

  • duanpang1987 2013-11-23 15:06
    关注

    try this:

    array_push ($newservices, $newservice);
    

    instead of:

    array_push ($newservices[count($newservices)], $newservice);
    

    because now you pass to the first argument of array_push an integer value not an array

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b