KoolReport's Forum

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

Simple columnRename for returned Mysql query #1592

Open Pauly Comtois opened this topic on on Aug 21, 2020 - 4 comments

Pauly Comtois commented on Aug 21, 2020

The columnRename function doesn't seem to be working for me. It's a very basic table. Is the ordering incorrect for pipe?

<?php

require_once '../koolreport/koolreport/core/autoload.php';

use \koolreport\KoolReport;
use \koolreport\processes\ColumnRename;

class Node19 extends KoolReport {

    public function settings()
    {

        return array(
            "dataSources"=>array(
                "node19sql"=>array(
                    'host' => 'localhost',
                    'username' => 'xxx',
                    'password' => 'xxx',
                    'dbname' => 'xxx',
                    'charset' => 'utf8',
                    'class' => "\koolreport\datasources\MySQLDataSource"
                ),
            )
        );
    }
    protected function setup()
    {
        $this->src('node19sql')
            ->query("SELECT * FROM node_161")
            ->pipe($this->dataStore('vendor_table_results'))
            ->pipe(new ColumnRename(array(
                "Column 0"=>"NODE ID",
                "Column 1"=>"NODE NAME",
                "Column 2"=>"Web Address",
                "Column 3"=>"URL FORMATTED",
                "Column 4"=>"ECODE",
                "Column 5"=>"DECODE",
            )));
    }
}
Pauly Comtois commented on Aug 21, 2020

FYI the column names are currently UUID's that are unreadable in a report, so they must be changed.

KoolReport commented on Aug 22, 2020

It is because of this line:

->pipe($this->dataStore('vendor_table_results'))

has been put in the middle so the pipe never reach ColumnRename. The dataStore should be at the end. So you do:

        $this->src('node19sql')
            ->query("SELECT * FROM node_161")
            ->pipe(new ColumnRename(array(
                "Column 0"=>"NODE ID",
                "Column 1"=>"NODE NAME",
                "Column 2"=>"Web Address",
                "Column 3"=>"URL FORMATTED",
                "Column 4"=>"ECODE",
                "Column 5"=>"DECODE",
            )))
            ->pipe($this->dataStore('vendor_table_results'));
Pauly Comtois commented on Aug 22, 2020

That did it, thanks! Can I pass in a variable that holds the array rather than typing it out? I would like to have the array built at run time through a separate query, since it could change.

Something like this?





    {
        $this->src('node19sql')
            ->query("SELECT * FROM node_161")
            ->pipe(new ColumnRename($column_id_array
            ))
            ->pipe($this->dataStore('vendor_table_results'));
    }
KoolReport commented on Aug 22, 2020

Definitely possible.

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
None yet

None