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 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)