Reputation: 379
Can someone help with with the following, im trying to fill array $a with data needed for my fusionchart graph. But after checking it with var_dump(), no data can be found.
the first query returns 6 brands, and the second query returns the sales for each brand in 2 rows. this is the format needed for my graph in fusioncharts.
$datum=array();
$a=array();
$stm3 = $pdo->prepare("SELECT DISTINCT brand FROM `weeks` WHERE `".$select."` = '".$zoeken."'");
$result = $stm3->execute();
$results = $stm3->fetchAll(PDO::FETCH_ASSOC);
foreach($results as $row) {
$stm4 = $pdo->prepare("SELECT SUM(`sales`) AS 'sales' FROM `weeks` WHERE `".$select."` = '".$zoeken."' AND `brand` = '".$row["brand"]."' GROUP by `brand`,`datum` ");
$stm4->execute();
$results1 = $stm4->fetchAll(PDO::FETCH_ASSOC);
foreach($results1 as $row1) {
array_push($a, array("seriesName"=> $row[0], "data"=>$row1));
}
}
array(3) { [0]=> array(0) { } 1=> array(2) { ["seriesName"]=> string(16) "brand1" ["data"]=> array(1) { ["sales"]=> string(5) "11806" } } [2]=> array(2) { ["seriesName"]=> string(16) "brand1" ["data"]=> array(1) { ["sales"]=> string(5) "16626" } } }
Upvotes: 2
Views: 81
Reputation: 4038
define $a first.. if it not defined..
like $a = array();
if it not defined already $a is null and array_push cant add items to null..
also you are getting only associative array values using
$results = $stm3->fetchAll(PDO::FETCH_ASSOC);
but you are refering indexed array
array_push($a, array("seriesName"=> $row[0], "data"=>$row1));
change
$results = $stm3->fetchAll(PDO::FETCH_ASSOC);
to
$results = $stm3->fetchAll(PDO::FETCH_BOTH);
Upvotes: 1