KoolReport's Forum

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

Single SQL column to Multiple Custom Column #2688

Open arawat opened this topic on on May 19, 2022 - 2 comments

arawat commented on May 19, 2022

Hi,

I have two SQL tables one for student id and their subjects

and one for their marks like below, comma separated values

so i take subject and position of marks from table one and from table two i convert comma separated values in array and by position i get the marks of respective subjects for a particular student, and further for particular student i create charts for each subjects.

i am new to kool report, how can i achieve this.

Thanks

Sebastian Morales commented on May 23, 2022

You can use a join sql query to join the 2 tables then use the Map process to split your "marks" column to multiple column like this:

$this->src(...)
->query($joinQuery)
->pipe(new \koolreport\processes\Map(array(
    "{value}" => function($row) {
        $marks = explode(",", $row["marks"]);
        foreach ($marks as $i => $mark) {
            $row["mark_" . $i] = $mark;
        }
        return $row;
    }
)))
->pipe($this->dataStore("marks"));

Then your datastore "marks" would have "mark_1", "mark_2", "mark_3", etc columns to draw chart together with column "student_id".

arawat commented on May 26, 2022

thank u very much.

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
solved

None