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:
$db->table('tyr_licenses')
->select('id, name, count(*) as hasLicence')
->leftjoin('tyr_licence_font', 'tyr_licence_font.id_licence = tyr_licenses.id')
->where('tyr_licence_font.id_font', '=' , 36)
->group('tyr_licence.id')
->all();
Do you know whats the problem?
Thanks!
texnixe
February 14, 2018, 8:03pm
2
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 = tyr_licenses.id')
->where('tyr_licence_font.id_font', '=' , 36)
->group('tyr_licence.id')
->all();
dump($items);
cabot
February 15, 2018, 7:24am
3
Hi,
I think it can be done using quotes for each coloumn in select (); This is my code
$db->table(‘tyr_licenses’)
->select(‘id’, ‘name’, ‘count(*) as hasLicence’)
->leftjoin(‘tyr_licence_font’, ‘tyr_licence_font.id_licence = tyr_licenses.id’)
->where(‘tyr_licence_font.id_font’, ‘=’ , 36)
->group(‘tyr_licence.id’)
->all();
Need to put qotes for each column in select();
Thanks
Thanks! But I found the problem… I called to a non-exist table in group()… Sorry
alexpi
August 10, 2020, 12:27pm
6
Where can I find these database methods in Kirby 3’s documentation?
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.