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);
}
}
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
Thats because $newservices[count($newservices)]
is not an array
Read docs here array_push
Just to fix the error you can do this
$newservices[count($newservices)] = array();
array_push ($newservices[count($newservices)], $newservice);
Try to replace this code
array_push ($newservices[count($newservices)], $newservice);
with
$newservices[count($newservices)] = $newservice;
The simplest way of adding an element/array to another array is this:
$newservices[] = $newservice;