KoolReport's Forum

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

Trouble with count() #2108

Open Richb201 opened this topic on on May 30, 2021 - 4 comments

Richb201 commented on May 30, 2021

This is showing zero rows when i know that there are two rows. Why?

        $this->src('substantiator')
            ->query("SELECT  bus_comp FROM business_components WHERE campaign='$campaign' AND email='$email' AND taxyear='$taxyear'")
            ->pipe(new ColumnRename(array(
                "bus_comp"=>"Business Component")))
            ->pipe($this->dataStore("business_components"));

        $iRc= $this->dataStore("business_components")->count();

KoolReport commented on May 30, 2021

In the setup() function, there is no data available. the query is not running at that time so there will be no data available yet.

More information of this is inside Life Cycle

If you really want the data to be available at that time you can use dataRequestSending() like below:

        $this->src('substantiator')
            ->query("SELECT  bus_comp FROM business_components WHERE campaign='$campaign' AND email='$email' AND taxyear='$taxyear'")
            ->pipe(new ColumnRename(array(
                "bus_comp"=>"Business Component")))
            ->pipe($this->dataStore("business_components"))
            ->requestDataSending();

        echo $this->dataStore("business_components")->count();
Richb201 commented on May 30, 2021

Thanks. Can you tell me where requestDataSending() is documented? Why don't you have a search box on your site?

Richb201 commented on May 30, 2021

Is there any way for me to just update a field in the datastore directly ?

Richb201 commented on May 30, 2021

I have created a table that I need for a report.

        $sql = "CREATE TABLE survey_results_BC_temp
            SELECT sr.taxyear,sr.user_email, sr.item, sr.campaign, sr.email, sr.qualified, COUNT(distinct sr.number_of_employees) as number_of_employees, e.w2_wages
              FROM survey_results sr JOIN employees e
              ON user_email=employee_email AND sr.taxyear=e.taxyear
              WHERE  item_type='BC' and sr.campaign=? 
              GROUP BY taxyear,user_email
              ";


        $query1 = $this->db->query($sql,$campaign);
        $sql ="ALTER TABLE survey_results_BC_temp
              ADD dollars_per_BC int default 0,
              ADD number_consultants int default 0,
              ADD number_contracts int default 0,
              ADD amount int default 0,
              ADD number_of_bus_comps int default 0"
             ;
        $query2 = $this->db->query($sql);

Besides the fields I already assembled, I need the total # of business_components used. To get this I have fallen back to mysql and used this. I of course would have preferred to have it created directly in the CREATE TABLE statement above for speed purposes. My code is already way too slow.

        $sql = "SELECT COUNT(bus_comp) as buscomp_count
                FROM business_components WHERE email = ? AND campaign = ? AND taxyear=(SELECT taxyear FROM survey_results_BC_temp WHERE campaign=? AND email = ?) ";
        $query = $this->db->query($sql, array($email,$campaign,$campaign,$email,));
        $row = $query->result();
        $buscomp_count=$row[0]->buscomp_count;

This directly gets the number of business components from a different table. Is there any way for me to directly insert the $buscomp_count into the field number_of_bus_comps in the survey_results_BC_temp datastore I will build?

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