How to make counting the number of elements for the statistics?

Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike

In General, I want to bring in a tree how many and which services were ordered and what categories.

3 of the table.
category (id , name, description )price (id cateory_id name unit ptice) and Orders (id name category_id price_id telephone date processed)

The tree itself I built relatively models

All orders : 43
<?php echo '<pre>'. print_r($orders, true).'
'?> Of them:
<?php foreach ($cat as $item) :?>
    <?php if ($item['id'] != 17): ?>
  • <?=$item['name']?> - 3
      <?php foreach ($price as $itemok) :?><?php if ($item['id'] == $itemok['category_id']): ?>
    • <?=$itemok['name']?>
    • <?php endif; ?><?php endforeach; ?>
  • <?php endif; ?>
<?php endforeach; ?>

But now I want to get next to each category and service number of orders(In the future, with the date boundaries)

Tried to push forich going on in the game. The tables are all connected
by | 12 views

2 Answers

0 like 0 dislike
Also faced this problem, but I have a tree of 4-5 levels, different variants apart, but stayed just for the individual queries
$query = Product::find(); $query->select(['category_id', 'count' => 'count(`id`)']); $query->visible(); $query->andWhere(['category_id' => $categoryIds]); $query->groupBy('category_id'); $query->asArray();

Got many products from each section

2. Request the entire tree in reverse order, so that the latter elements were the descendants, then a simple loop bypassed all the wood and added a number of elements, if changed level or parent then reset
0 like 0 dislike
Create property $ordersCount in this category, add a dB query (LEFT JOIN and COUNT()) so that the number of orders are equivalent ordersCount, then this property bring to the table.

Related questions

110,608 questions
257,187 answers
40,796 users