Keyword

Show Total Number of Author Hits

  • Russell English
  • Russell English's Avatar Topic Author
  • Offline
  • New Member
More
7 years 6 months ago #158664 by Russell English
Show Total Number of Author Hits was created by Russell English
I have a requirement where I want to show the total number of hits that a user's items have been read. For example, if they have ten K2 items, each have been read 10 times, then I want to show the total number (in this case 100) of hits that users total items have been read.

K2 has a variable, which I can echo for each of the items:

<?php echo $item->hits; ?>

But I need a way to add all of the authors items hits up.

Anyone know of any solution?

Please Log in or Create an account to join the conversation.

  • Russell English
  • Russell English's Avatar Topic Author
  • Offline
  • New Member
More
7 years 6 months ago #158667 by Russell English
Replied by Russell English on topic Show Total Number of Author Hits
To fix this I put the following:

$db = JFactory::getDbo();

$query = $db->getQuery(true);
$query->select($db->qn('hits'))
->from($db->qn('#__k2_items'))
->where($db->qn('created_by') . ' = ' . $db->q($this->user->id));
$db->setQuery($query);

$results = $db->loadObjectList();

$sum = 0;
foreach ($results as $key => $val)
{
$sum+= $val->hits;
}

echo number_format($sum);

into /templates/template_name/html/com_k2/templates/default/user.php

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 6 months ago #158668 by Krikor Boghossian
Replied by Krikor Boghossian on topic Show Total Number of Author Hits
Nice one Russell :)

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum