• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.

Number of images in each category ?

SQL:
SELECT i.image_category_id id, c.category_name name, COUNT(1) count
FROM chv_images i
LEFT JOIN chv_categories c ON c.category_id = i.image_category_id
WHERE i.image_category_id IS NOT NULL
GROUP BY i.image_category_id;

1530721329730.png

Do please note that this is an expensive query. Don't call it on every request.
 
You must execute that query using CHV\DB. I must insist, DO NOT call that query on every request. It will eat like 2 seconds of request time and it could compromise your server (ddos).

PHP:
$fetch = CHV\DB::queryFetchAll('
SELECT i.image_category_id id, c.category_name name, COUNT(1) count
FROM chv_images i
LEFT JOIN chv_categories c ON c.category_id = i.image_category_id
WHERE i.image_category_id IS NOT NULL
GROUP BY i.image_category_id;');

$fetch will contain the resultset array.
 
Back
Top