I'm trying to get the count of table from another tables using cakephp3 , but i have get an error
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' ) AS Transactions__COUNT( ) FROM transactions Transactions LEFT JOIN transactio' at line 1
I don't know what's wrong with my code !!
here's my controller :
$data = $this->Transactions->find(
'all',
array(
'fields' => array('COUNT(*)'),
'group' => array('transactions_type_id'),
'contain' => array('TransactionsTypes')
) );
and here's my ctp:
<?php
foreach ($data as $transactionsType) {
?>
<li>
<p class="clearfix"><i class="icon-radio-checked text-info"></i><b><?php echo $transactionsType['title'] ?> </b><span>210</span>
</p>
<div class="progress progress-md">
<div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="8" aria-valuemin="0" aria-valuemax="100" style="width: 8%"><span class="sr-only">10% Complete (success)</span>
</div>
</div>
</li>
<?php }
?>
You just can use count()
function.
$count=TableRegistry::get('Transactions')
->find()
->contain('TransactionsTypes')
->group('Transactions.transactions_type_id')
->count();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.