0

I need to fill a multidimensional array and here is my code I have so far for it.

while($num > $i)
{
        $default[$i]=0;
        $defaultcounter=0;
        $default2[$i]=0;
        $default3[$i]=0;
        $query="Select * from `issues` WHERE `app`='" . $applist[$i] . "'" . "AND `startmonth`='". $month ."' ORDER BY `id` ASC";
        $result=mysql_query($query);
        while($row = mysql_fetch_array($result))
        {
            $downtime[$i]+=$row['duration'];
            $default2[$i]++;    //Number of Incidents Variable
            $defaultcouinter++;
            $times[$i] = array();
            $times[$i][$defaultcounter[$i]]=$row['startday'].$row['starttime'];
        }
        $appavail[$i]=100 -(ceil($downtime[$i] * 100 / $totaltime));
        $default[$i] = (ceil($downtime[$i] / $defaultcounter));
        $i++;
    }

Apparently I am not doing the array assignment correct. I need to to have my number of rows counted with the $i variable outside of my while then inside the while the defaultcounter will be keeping up with the column. I tried just doing a $time[$i][defaultcounter] and it didn't like it. Whats the proper syntax for assigning a multidimensional array?

Thanks

1
  • 2
    Querying inside of a loop is bad practice. Commented Dec 2, 2011 at 6:13

1 Answer 1

2

$times[$i] = array() should be out (before) the while loop unless you want it redefining $times as an empty array in each iteration (reseting values). Apart from that, you're assigning the values correct, although it looks a bit odd (not sure what you want to achieve there). This are the general formulas, should give you an idea:

$array[] = $subarray;
$array[$subarray] = $value;
$array[$subarray][] = $value;
$array[$subarray][$i] = $value;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.