Advertisement:

Author Topic: Count items by mail in ADMIN. How to?  (Read 476 times)

butterfly

  • Jr. Member
  • **
  • Posts: 80
Count items by mail in ADMIN. How to?
« on: December 15, 2018, 05:54:27 pm »
Hi

Could you help me build db query to count item by mail?
I want to display this value in admin on listing page like:
mail: xxx@xxx.com
items counter: 23

E-mail I can find by query:
Code: [Select]
    $item                       = $conn->osc_dbFetchResult("SELECT s_contact_email FROM osc_t_item WHERE pk_i_id = '%d'", $aRow['pk_i_id'] );
    $item_mail                  = $item2['s_contact_email'];


But how to count items by mail?

patrickFromCroatia

  • Hero Member
  • *****
  • Posts: 698
  • OSC Market review time makes me wanna cry...
Re: Count items by mail in ADMIN. How to?
« Reply #1 on: December 15, 2018, 07:21:10 pm »
Hello,

You want to count how many items have a specific contact mail?
A MySQL query would look like like this "SELECT COUNT(*) AS count FROM oc_t_item WHERE s_contact_email = 'mail@gmail.com';".

Regards.

butterfly

  • Jr. Member
  • **
  • Posts: 80
Re: Count items by mail in ADMIN. How to?
« Reply #2 on: December 17, 2018, 03:44:24 pm »
@patrickFromCroatia

Exactly, I want to count how many items have a specific contact mail?
Your code do job.

But, please, help my to find how many ACTIVE items have a specific contact mail?

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1618
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Count items by mail in ADMIN. How to?
« Reply #3 on: December 17, 2018, 10:37:57 pm »
Isn't this included in the core? It has some bugs, but I solved them and posted in the forum the solution. Don't ask me to find the topic:))

patrickFromCroatia

  • Hero Member
  • *****
  • Posts: 698
  • OSC Market review time makes me wanna cry...
Re: Count items by mail in ADMIN. How to?
« Reply #4 on: December 18, 2018, 03:33:58 pm »
Try this "SELECT COUNT(*) AS count FROM oc_t_item WHERE s_contact_email = 'mail@gmail.com' AND b_active = 1 AND b_enabled = 1 AND b_spam = 0;"

Don't know about the core function...

Regards.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1618
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Count items by mail in ADMIN. How to?
« Reply #5 on: December 18, 2018, 09:19:26 pm »
The core implemented a db table column with this number and it updates that field with each new published , deleted item etc. That is good when having many listings, when a query only for counting would not be verry fast.
« Last Edit: December 19, 2018, 10:23:17 am by marius-ciclistu »

patrickFromCroatia

  • Hero Member
  • *****
  • Posts: 698
  • OSC Market review time makes me wanna cry...
Re: Count items by mail in ADMIN. How to?
« Reply #6 on: December 18, 2018, 11:33:20 pm »
Maybe this then: "SELECT i_items FROM oc_t_user WHERE s_email = 'mail@gmail.com'".

Regards.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1618
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Count items by mail in ADMIN. How to?
« Reply #7 on: December 19, 2018, 10:24:34 am »
The info should be available in user array without extra query.

patrickFromCroatia

  • Hero Member
  • *****
  • Posts: 698
  • OSC Market review time makes me wanna cry...
Re: Count items by mail in ADMIN. How to?
« Reply #8 on: December 20, 2018, 12:40:02 am »
The info should be available in user array without extra query.

I forgot that. :)

If you have a user array already (osc_user()) then you can use osc_user()['i_items'].
You can also use user DAO class to get that info:

Code: [Select]
<?php
$user 
User::newInstance()->findByEmail('mail');
$items $user['i_items'];

So basically there's a thousand solutions, pick the one that suits the best. ;)

Regards.