jimie VIP
Total posts: 531
08 Apr 2014 08:59

Hello Sergey

Can you provide me the code I need to use in the statistics module to display this statistics ?

  1. Total numbers of listings in that section ( this probably already a option in the module )
  2. Total numbers of new listings in that section
  3. Total number of listings which are about to expire in that section

rgds

Last Modified: 22 Jun 2014


Sergey
Total posts: 13,748
08 Apr 2014 09:55

jimie Total numbers of listings in that section ( this probably already a option in the module )

Count all listings in section

$sql = "SELECT count(*) FROM #__js_res_record WHERE section_id = 1";

jimie Total numbers of new listings in that section

Count listings for last 3 days.

$sql = "SELECT count(*) FROM #__js_res_record WHERE section_id = 1 AND ctime > NOW() - INTERVAL 3 DAY";

jimie Total number of listings which are about to expire in that section

Count listings that expire in 3 days

$sql = "SELECT count(*) FROM #__js_res_record WHERE section_id = 1 AND extime > NOW() AND extime < NOW() + INTERVAL 3 DAY";

All $sql queries works like this.

$db = Jfactory::getDbo();
$db->setQuery($sql);
echo $db->loadResult();

And of course you have to change 1 to real section ID.


jimie VIP
Total posts: 531
08 Apr 2014 10:05

Big thanks Sergey!


pepperstreet VIP
Total posts: 3,837
08 Apr 2014 12:43

+1

BTW, if the SQLs are called in a custom module or stats module... how does one cache such infos? Is there a Cobalt method or utilize J! core?


Sergey
Total posts: 13,748
08 Apr 2014 16:34

You do not need to cache it I think. Because you show it only in one place.


jimie VIP
Total posts: 531
20 Jun 2014 10:36

Hello Sergey,

What about updating those queries to show only published items but not those which are not published ?

rgds


pepperstreet VIP
Total posts: 3,837
22 Jun 2014 01:46

jimie ... show only published items ...?

Simply add the following parameter:

AND published = 1

Example Section 99:

$sql = "SELECT count(*) FROM #__js_res_record WHERE section_id = 99 AND published = 1";
Powered by Cobalt