Why can't I assign any variable to the return value of a function in pChart?

I am trying to assign the return value from a method to an array, and in a second step, place that array in the addPoints () method for pChart.

I am currently 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 data in pChart I run this:

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

      

As an output, I get the default html icon, as if I don't find the picture I'm looking for.

What really interests me 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 an image. But I couldn't even run it when I tried:

$myData->addPoints(array(getDailyUsage(1), getDailyUsage(2)), "Absissa")

      

+3


source to share


1 answer


I need help solving my problem and would like to share this solution: I had to check the html source in a browser. The .php file displaying the image showed an error. The problem was that the file containing the connection information was not included.



I recommend you look at the image / file if you are working with pChart to avoid these errors.

0


source







All Articles