I would like to use the following:

$row1 = mysql_fetch_array($genDay[0][0]);
$row2 = mysql_fetch_array($genDay[0][1]);
$row3 = mysql_fetch_array($genDay[0][2]);
$row4 = mysql_fetch_array($genDay[0][3]);
$row5 = mysql_fetch_array($genDay[0][4]);
$row6 = mysql_fetch_array($genDay[0][5]);
$row7 = mysql_fetch_array($genDay[0][6]);
$row8 = mysql_fetch_array($genDay[1][0]);
$row9 = mysql_fetch_array($genDay[1][1]);
$row10 = mysql_fetch_array($genDay[1][2]);
$row11 = mysql_fetch_array($genDay[1][3]);
$row12 = mysql_fetch_array($genDay[1][4]);
$row13 = mysql_fetch_array($genDay[1][5]);
$row14 = mysql_fetch_array($genDay[1][6]);

Like this:

$row[$q] = mysql_fetch_array($genDay[$g][$x]);

Ultimately I want to use this to echo the result as follows:

<?php echo $row[0]['SUM(itemQty)']; ?>

Which doesn't work.

UPDATE Here is the code which I'm using at the moment:

$dayD = array("MonD","TueD","WedD","ThuD","FriD","SatD","SunD");
$genre = array("Rock","Metal","Alternative","Modern");
$genDay = array(0=>array("Mon","Tue","Wed","Thu","Fri","Sat","Sun"),
                 1=>array("Mon","Tue","Wed","Thu","Fri","Sat","Sun"),
                 2=>array("Mon","Tue","Wed","Thu","Fri","Sat","Sun"),
                 3=>array("Mon","Tue","Wed","Thu","Fri","Sat","Sun"));

$date = strtotime($_POST['fromDate']);
$dayD[0] = date('Y-m-d', strtotime("last Monday", $date));
$monDSTR = strtotime($dayD[0]);
$c=0;

for ($g=0; $g<=3; $g++)
{
    $genDay[$g][0] = mysql_query("SELECT SUM(itemQty) FROM product_sales WHERE itemGenre='" . $genre[$g] . "' AND sale_date BETWEEN '" . $dayD[0] . " 00:00:00' AND '" . $dayD[0] . " 23:59:59'");
    for ($x=1; $x<=6; $x++)
    {
        $dayD[$x] = date('Y-m-d', strtotime("+" . $x . " day", $monDSTR));
        $genDay[$g][$x] = mysql_query("SELECT SUM(itemQty) FROM product_sales WHERE itemGenre='" . $genre[$g] . "' AND sale_date BETWEEN '" . $dayD[$x] . " 00:00:00' AND '" . $dayD[$x] . " 23:59:59'");
        /*
        $cell[$c] = mysql_fetch_array($genDay[$g][$x]);
        $c++;
        */
    }
}   

/*echo $cell[0]['SUM(itemQty)'];*/

The "echo $cell[0]['SUM(itemQty)'];" is echoed in a table cell.

What the code is for The code is to fill table cells from Monday to Tuesday with the total sales of that day. Where each row will be a different music genre.

link|improve this question
$row is a result. You can't pass additional database queries as keys for arrays and expect to get a result. What is $genDay? What are $g and $x? What is it supposed to do? More code and intent please. – Zenbait May 4 at 18:03
feedback

2 Answers

mysql_fetch_array() returns a single row from the recordset.

The normal way to use it (if you expect there to be more than one row in the recordset) is with a loop.

while ($row = mysql_fetch_array($recordset)) {
   //do something with the $row
}
link|improve this answer
Thanks, guess I just didn't understand how mysql_fetch_array() works. Found a working solution. Will post it as soon as I can answer my own question. – TKD May 4 at 19:09
feedback

Based on the code in the question, this is the solution I went with:

$rowD = array();    
    $r=0;
    for ($g=0; $g<=3; $g++)
    {
        for ($x=0; $x<=6; $x++)
        {           
            $row = mysql_fetch_array($genDay[$g][$x]);
            $rowD[$r] = $row['SUM(itemQty)'];
            if ($rowD[$r] == "")
            {
                $rowD[$r] = 0;
            }
            $r++;
        }
    }

    echo "Monday Total Sales: " . $rowD[0];
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.