KoolReport's Forum

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

Update Column in DB #2465

Closed najam opened this topic on on Nov 26, 2021 - 2 comments

najam commented on Nov 26, 2021

Hi Everyone,

Does somebody know how to update the database columns based on input via a text box?

I have a report where the user enters a value into a text box "title". I want to save this title value into the database.

I want to know where exactly this update code needs to place and how to link it with the "load" button event so that this value can be saved into the database.

$this->src('REPORTS')->query(

            DB::table('members_report')
                ->where('member_id', $this->params["id"])
                ->update(
                    ['report_title' => $this->params["report_title"] ]
                )
        );

This code is working fine while I placed it in the setup function of the report for testing.

It would be good to see a working example.

Sebastian Morales commented on Nov 29, 2021

You can also write raw sql query to be used with input parameters like this:

//MyReport.php
$this->src('REPORTS')->query("
    update member_report set report_title=:report_title where member_id = :member_id
")
->params([
    ":member_id" => $this->params["id"],
    ":report_title" => $this->params["report_title"],
])
->pipe($this->dataStore("updateResult"));
;

This command could be placed in a report setup or even in the report view if you add method requestDataSending() at the end, which execute the sql query right at once:

//MyReport.view.php
$this->src('REPORTS')->query("
    update member_report set report_title=:report_title where member_id = :member_id
")
->params([
    ":member_id" => $this->params["id"],
    ":report_title" => $this->params["report_title"],
])
->pipe($this->dataStore("updateResult"))
->requestDataSending();
najam commented on Dec 2, 2021

Perfect. Thanks Sebastian Morales

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