Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
I have a clonable template with a custom field called status that takes in two params..satisfied and notsosatisfied and I want to display monthly stats in % of how many are satisfied and how many are notsosatisfied out of all from that month.

This is my code for displaying the archives:

Code: Select all
  <cms:archives masterpage='feedback.php' type='monthly'> 
      <li>
         <a href="<cms:add_querystring "<cms:link 'stats.php' />" "start_on=<cms:date k_archive_date format='Ym'/>" />"><cms:date k_archive_date format='F Y' /> (<cms:show k_archive_count />)</a>
      </li>
  </cms:archives>


Listing code:

Code: Select all
<cms:set satisfied_clients="<cms:pages masterpage='feedback.php' custom_field='status=satisfied' count_only='1' start_on="<cms:gpc 'start_on' method='get' />" stop_before=k_next_archive_date/>" 'global'/>    
 
<cms:set unsatisfied_clients="<cms:pages masterpage='feedback.php' custom_field='status=notsosatisfied' count_only='1' start_on="<cms:gpc 'start_on' method='get' />" stop_before=k_next_archive_date/>" 'global' />   

<cms:set all_clients="<cms:pages masterpage='feedback.php' count_only='1' start_on="<cms:gpc 'start_on' method='get' />" stop_before=k_next_archive_date/>" 'global' />   
   
<cms:php>
    global $satisfied, $unsatisfied;
    $satisfied = round((<cms:show satisfied_clients />/<cms:show all_clients />)*100);
    $unsatisfied = round((<cms:show unsatisfied_clients />/<cms:show all_clients />)*100);
</cms:php>   


Satisfied:
<cms:php>
    global $satisfied;
    echo $satisfied;
</cms:php>%

Not so satisfied:
<cms:php>
    global $unsatisfied;
    echo $unsatisfied;
</cms:php>%

Total: <cms:show all_clients />


The thing is that when testing with this scenario:
5 pages added in 01.2018
1 page added in 01.2017

This is ok: When I press on January 2018 (5) I get Satisfied: 80% Not so satisfied: 20% Total: 5
But when I press on January 2017 (1) i get the stats for all 6 pages: Satisfied: 67% Not so satisfied: 33% Total: 6

..when it should have been Satisfied: 0% Not so satisfied: 100% Total: 1

Where am I going wrong with this?
From what I can see, there appear to be two problems in your code -

1. The code in stats.php is making use of a variable named 'k_next_archive_date' -
<cms:set satisfied_clients="<cms:pages masterpage='feedback.php' custom_field='status=satisfied' count_only='1' start_on="<cms:gpc 'start_on' method='get' />" stop_before=k_next_archive_date/>" 'global'/>

That variable is available only in 'archive-view' so, I think, your code is working with blank values for the stop_before.

You should pass the 'stop_before' value also as querystring parameter.

2. You are passing dates formatted as 'Ym' -
<cms:date k_archive_date format='Ym'/>

Couch tags expect dates only in 'Y-m-d' format. Please change this also.

Hope it helps.
KK wrote: From what I can see, there appear to be two problems in your code


Fixed my query string to include the next archive date:
Code: Select all
<a href="<cms:add_querystring "<cms:link 'stats.php' />" "start_on=<cms:show k_archive_date/>&stop_before=<cms:show k_next_archive_date/>"  />"><cms:date k_archive_date format='F Y' /> (<cms:show k_archive_count />)</a>


...and used it when fetching pages:

Code: Select all
start_on="<cms:gpc 'start_on' method='get' />" stop_before="<cms:gpc 'stop_before' method='get' />"


Thank you :)
3 posts Page 1 of 1

Who is online

In total there are 2 users online :: 1 registered, 0 hidden and 1 guest
(based on users active over the past 5 minutes)

Users browsing this forum: Majestic-12 [Bot] and 1 guest