KoolReport's Forum

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

No data available in table.. #2901

Closed Rick Flower opened this topic on on Dec 13, 2022 - 2 comments

Rick Flower commented on Dec 13, 2022

ok.. so I got past my first hurdle with creating my first report and at least I'm not getting PHP errors.. but I'm not getting any data either and I'm not sure why.. My code is below -- I'm sure it's something easy but I'm lost.. My code is obviously not final -- I just want to see a little of my data and I can go from there..

<?php 

require_once "MyUserReport.php";

$report = new MyUserReport;
$report->run()->render();

?>
<?php
require_once "load.koolreport.php";

use \koolreport\processes\Custom;

function decryptField($stringToDecrypt)
{
    <my code to decrypt fields -- removed here>
    return($decrypted_string);
}



class MyUserReport extends \koolreport\KoolReport
{
    protected function settings()
    {
        return array(
            "dataSources"=>array(
                "mydatabase"=>array(
                    "connectionString"=>"mysql:host=localhost;dbname=mydatabase",
                    "username"=>"<user>",
                    "password"=>"<pw>",
                    "charset"=>"utf8mb4"
                )
            )
        );
    }

    protected function setup()
    {
        $this->src('mydatabase')
        ->query("select marital, name, address from users")

        ->pipe(new Custom(function($row) {
            $row["name"]    = decryptField($row["name"]);
            $row["address"] = decryptField($row["address"]);
        }))

        ->pipe($this->dataStore("users"));
    }
}
<?php
use \koolreport\widgets\koolphp\Table;
?>

<div class='report-content'>
    <div class="text-center">
        <h1>Users by Country</h1>
        <p class="lead">The report show total sales on each countries</p>
    </div>

    <?php
    Table::create(array(
        "dataStore"=>$this->dataStore("users"),
        "columns"=>array(
            "marital"=>array(
                "label"=>"marital status",
                "type"=>"string"
            ),
            "name"=>array(
                "label"=>"Name"
            ),
            "address"=>array(
                "label"=>"Address"
            )
        ),
        "paging"=>array(
            "pageSize"=>50,
        ),
        "cssClass"=>array(
            "table"=>"table table-bordered table-striped"
        )
    ));
    ?>
</div>
Rick Flower commented on Dec 13, 2022

I found another thread suggesting to add the following line to my report view :

echo "data = "; print_r($this->dataStore('users')->data());

and it says the array is empty..

data = Array ( )

what causes that? I've verified that my query is fine in phpmyadmin w/o issue.

Rick Flower commented on Dec 13, 2022

ok.. figured it out.. I forgot to put the "return $row" as the last line in my Custom function within setup(). Now it's working just fine.. thx

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