KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Trying to access array offset on value of type null at PlannerGoals.view.php:352) #1261

Closed paulo opened this topic on on Jan 16, 2020 - 4 comments

paulo commented on Jan 16, 2020

I am not sure why I am getting this error. I don't think there is any 'null' value coming back. I even checked with ifnull(paid_on,0) Values work fine if I list them as columns, but when I try to capture to compare and format another column, I get this error. Here is what I'm trying to do:

    "TotalEst"=>array(
                "type"=>"number",
                "decimals"=>2,
                "footer"=>"sum",
                "formatValue"=> function($value,$row) {
                    // $tourID = $value; // or = $row["tourid"];
                    $tourID =  $row["TotalEst"];
                    $tourName = $row["paid_on"];
                    $color = $tourID>=$tourName?"#718c00":"#e83e8c";
                    return "<span style='color:$color'>$".number_format($value)."</span>";

                },
            ),
            "paid_on"=>array(
                "type"=>"number",
                "decimals"=>2,
                "footer"=>"sum"
            ),

If I remove the formatValue clause, it works fine and it shows the TotalEst AND the paid_on. Why I can't access the TotalEst through $tourID = $row["TotalEst"]; and/or $tourName = $row["paid_on"]; Note: paid_o comes from the database select query, TotalEst is calculated using: ->pipe(new CalculatedColumn(array(

                 "TotalEst"=>function($data){
                     return ( $data["ETPlannerEst"]+$data["ETQuoterEst"]);
                 },
             )))

what am I doing wrong? thank you

KoolReport commented on Jan 17, 2020

It happens at footer, when the formatValue is called but only $value of total is available. You can check if $row is null, if it is null then do not do the calculation, just provide the format for the $value.

paulo commented on Jan 17, 2020

Thank you. I've added if($row!=null) BUT now I don't see the totals at the bottom.... How can I format and keep the totals at the bottom? thank you !

       "TotalEst"=>array(
                "type"=>"number",
                "decimals"=>2,
                "footer"=>"sum",
                "formatValue"=> function($value,$row) {
                    if ($row!=null) {
                        // $tourID = $value; // or = $row["tourid"];
                        $tourID = $row["TotalEst"];
                        $tourName = $row["paid_on"];
                        $color = $tourID >= $tourName ? "#718c00" : "#FF0000";
                        return "<span style='color:$color'>$" . number_format($value) . "</span>";
                    }
                },
            ),
KoolReport commented on Jan 17, 2020

You should do:

if ($row!=null)
{
                        // $tourID = $value; // or = $row["tourid"];
                        $tourID = $row["TotalEst"];
                        $tourName = $row["paid_on"];
                        $color = $tourID >= $tourName ? "#718c00" : "#FF0000";
                        return "<span style='color:$color'>$" . number_format($value) . "</span>";
}
else
{
    return "<span style='color:#000'>$" . number_format($value) . "</span>";
}
paulo commented on Jan 17, 2020

thank you very much. It worked now!

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None