View Issue Details

This bug affects 2 person(s).
IDProjectCategoryView StatusLast Update
17647Bug reportsStatisticspublic2021-12-01 11:27
Reportersteffen.moser Assigned ToDenisChenu  
Status resolvedResolutionfixed 
Product Version5.x 
Summary17647: Strange sort order of question groups in simple statistics
DescriptionThe order of the question groups in the statistics feature isn’t the same as the survey question group order itself. This happens only in one survey. Other surveys do not show this behavior. We do not know why this survey is affected.

Maybe it is related to the number of questions in a question group.
Steps To ReproduceSteps to reproduce
Open an affected survey. We do not know how to reproduce. Maybe it depends on the order of records in the database or on the relation of the number of questions in the question groups.

Expected result
The question groups in the statistics feature should be in the order of the question groups.

Actual result
The question groups are in a different order.

The helper function "groupOrderThenQuestionOrder($a, $b)" defined in "application/helpers/common_helper.php" has an "if" clause which is never entered [1], so the sorting algorithm in [2] does not order by question group as the first criteria. It happens due to the fact that the array attribute "group_order" is neither in $a nor in $b (which are $rows).

In contrast to the attribute "question_order", the attribute "group_order" is in a subarray called "$group".

Therefore, the function should be as follows:

function groupOrderThenQuestionOrder($a, $b)
    if (isset($a->group['group_order']) && isset($b->group['group_order'])) {
        $GroupResult = strnatcasecmp($a->group['group_order'], $b->group['group_order']);
    } else {
        $GroupResult = "";
    if ($GroupResult == 0) {
        $TitleResult = strnatcasecmp($a["question_order"], $b["qutoestion_order"]);
        return $TitleResult;
    return $GroupResult;

When patching the function as mentioned above, the problem is gone. The problem looks the same as the one mentioned in [3].

TagsNo tags attached.
Bug heat14
Complete LimeSurvey version number (& build)LimeSurvey Community Edition Version 5.1.14+210927
I will donate to the project if issue is resolvedNo
BrowserFirefox 92.0.1, 64-Bit, Linux (but happens with Chrome on macOS in the same way)
Database type & versionMySQL 5.7.34
Server OS (if known)Oracle Solaris 11.4 SRU 37
Webserver software & version (if known)Apache 2.4.48
PHP VersionPHP 7.4.15

Users monitoring this issue

User List DarioRoig




2021-10-04 12:18

administrator   ~66739

Can you open a pull request with this change, please?


2021-11-12 10:04

developer   ~67268

Last edited: 2021-11-12 15:36

My opinion : we must request by good order by default :

My pinion : request is OK, why update order after ? For group order at 0 ?

Stay must use same order tha n all other.

1st step : find way to reproduce issue (i think update order of group just before activate can be OK).


2021-11-12 15:12

developer   ~67279

Last edited: 2021-11-12 15:36

@steffen.moser : can you check the order set for each group for this survey ?
Same order for some Group ? Order set to null or 0 ?


2021-11-12 15:36

developer   ~67280

Last edited: 2021-11-12 15:36

Issue in **simple** statistics

Create G1 with G1Q1
Create G2 with G2Q1
Reorder with G2 before G1
Seems OK but not in simple statitics


2021-11-22 17:19

developer   ~67479

Fix committed to master branch:


2021-12-01 09:26

reporter   ~67618

Hi Denis, there is a little bug, in postgres group is a reserved word, we can't use group as an table alias.

 'condition' => 't.sid=:sid',
                    'order' => 'group.group_order,question_order',
                    'params' => array(':sid' => $surveyid)


2021-12-01 11:27

developer   ~67633

@DarioRoig : can you

1. Open another issue
2. test with 'order' => 'group_order,question_order', in place of ?

Thank you .

Related Changesets

LimeSurvey: master 7238a601

2021-11-22 17:19:18


Committer: GitHub Details Diff
Fixed issue 17647: Strange sort order of question groups in statistics (#2143)

Dev: order is already set in request for run
Dev: fix request for simple statistics
Dev: check where function is used to add it in comment
Dev: Some clean up on quick stat logic
Affected Issues
mod - application/controllers/admin/statistics.php Diff File
mod - application/helpers/common_helper.php Diff File
mod - application/helpers/frontend_helper.php Diff File
mod - application/models/Question.php Diff File

Issue History

Date Modified Username Field Change
2021-10-04 02:34 steffen.moser New Issue
2021-10-04 08:23 galads Assigned To => galads
2021-10-04 08:23 galads Status new => assigned
2021-10-04 08:24 galads Assigned To galads => ollehar
2021-10-04 08:24 galads Status assigned => new
2021-10-04 08:24 galads Status new => assigned
2021-10-04 12:18 ollehar Note Added: 66739
2021-10-04 12:18 ollehar Bug heat 0 => 2
2021-11-12 10:04 DenisChenu Note Added: 67268
2021-11-12 10:04 DenisChenu Bug heat 2 => 4
2021-11-12 15:12 DenisChenu Note Added: 67279
2021-11-12 15:36 DenisChenu Note Added: 67280
2021-11-12 15:36 DenisChenu Summary Strange sort order of question groups in statistics => Strange sort order of question groups in simple statistics
2021-11-22 17:19 DenisChenu Changeset attached => LimeSurvey master 7238a601
2021-11-22 17:19 DenisChenu Note Added: 67479
2021-11-22 17:19 DenisChenu Assigned To ollehar => DenisChenu
2021-11-22 17:19 DenisChenu Resolution open => fixed
2021-11-22 17:21 ollehar Status assigned => resolved
2021-12-01 09:22 DarioRoig Issue Monitored: DarioRoig
2021-12-01 09:22 DarioRoig Bug heat 4 => 12
2021-12-01 09:26 DarioRoig Note Added: 67618
2021-12-01 09:26 DarioRoig Bug heat 12 => 14
2021-12-01 11:27 DenisChenu Note Added: 67633