3

I'm trying to assign a return value from a method to an array and in a second step to place this array into the addPoints() method of pChart.

Right now I'm using the following code:

$dataUsage = array();
for ($i = 1; $i < 31; $i++) {
        $dataUsage[$i - 1] = getDailyUsage($i);
}
$dataUsage[30] = getDailyUsage(31);

The getDailyUsage method looks like this:

function getPeriod() {
    return date("Y-m");
}

function getDailyUsage($day) {
        $var = getPeriod() . "-" . $day;
        global $pdo;
        $sql = "SELECT COUNT(  `id` ) FROM  `logs` WHERE timestamp = '$var'";
        $q = $pdo->prepare($sql);
        $q->execute();
        $q->setFetchMode(PDO::FETCH_ASSOC);
        $number = $q->fetchColumn(0);
        return $number;
}

To display the data into the pChart I'm running this:

$myData->addPoints($dataUsage, "Serie2");

As output I'm getting the default html icon as if I'm not finding the picture I'm looking for.

What really makes me curious is that I don't get any errors if I run this code:

$array = array();
for ($i = 1; $i < 31; $i++) {
    $array[$i - 1] = $i;
}
$array[30] = 31;

$myData->addPoints($array, "Absissa");

Since this is my first post I'm looking for tips to improve my questions, so feel free to leave a comment.

Edit: If I use:

$dataUsage = array();
for ($i = 1; $i < 31; $i++) {
        $dataUsage[$i - 1] = $i;
}
$dataUsage[30] = $i;

I can draw the image. But I couldn't even run it when I tried:

$myData->addPoints(array(getDailyUsage(1), getDailyUsage(2)), "Absissa")
Peter
  • 1,844
  • 2
  • 31
  • 55
  • I'd recommend to go through the process and echo out stuff as you go through it. This will help you find where the source of you problem is! I'd recommend looking at the function array_push if you are creating a new array and are trying to add stuff to it :) – Ramo Mislimi May 06 '15 at 17:59
  • The problem is that the array is technically correct, but I can't fill it with the return value of getDailyUsage() – Peter May 06 '15 at 18:08

1 Answers1

0

I got help for my problem and want to share the solution: I had to check for the html source in the browser. The .php file which displays the picture showed the error. Problem was that the file, which contains the connection information wasn't included.

I recommend you to look at the picture / file if you're working with pChart to avoid those errors.

Peter
  • 1,844
  • 2
  • 31
  • 55