How can i select a count column with database

Hi everyone,
I did this query to take the id, name and a count column but the query gives me “1” instead of an object to work with it.

That’s my code:

                    ->select('id, name, count(*) as hasLicence')
                    ->leftjoin('tyr_licence_font', 'tyr_licence_font.id_licence =')
                    ->where('tyr_licence_font.id_font', '=' , 36)

Do you know whats the problem?

You have to wrap count(*) within backticks:

$items = $db->table('tyr_licenses')
                    ->select('name, id, `count(*)` as hasLicense')
                    ->leftjoin('tyr_licence_font', 'tyr_licence_font.id_licence =')
                    ->where('tyr_licence_font.id_font', '=' , 36)

I think it can be done using quotes for each coloumn in select (); This is my code

->select(‘id’, ‘name’, ‘count(*) as hasLicence’)
->leftjoin(‘tyr_licence_font’, ‘tyr_licence_font.id_licence =’)
->where(‘tyr_licence_font.id_font’, ‘=’ , 36)

Need to put qotes for each column in select();


No, that doesn’t work.

Thanks! But I found the problem… I called to a non-exist table in group()… Sorry

Where can I find these database methods in Kirby 3’s documentation?

It’s a bit difficult:

1 Like

Or look at K3-Docs Guide: Database

Those are far from complete

1 Like

With Kirby 3.4.0, we have started refactoring the Database classes and we will continue with this in Kirby 3.5.0. The plan is to rewrite the guide with this second refactoring step as well.