Using ssp class complex function giving undefined offset: 0 error

Using ssp class complex function giving undefined offset: 0 error

abdulmanan0331abdulmanan0331 Posts: 5Questions: 1Answers: 0

I am using Datatables v1.10.19 to fetch pipeline data using server side processing.I am using WHERE clause in complex function as follows:

        $where = "recipient='".$recipient."' AND grouped='' GROUP BY id DESC";
        echo json_encode(
            SSP::complex( $_GET, $sql_details, $table, $primaryKey, $columns, null, $where )
        );

Everything is working fine but when there are no rows in my table i am getting the following errors:

Undefined offset: 0 in C:\MAMP\htdocs\core\ssp.class.php on line 351
Undefined offset: 0 in C:\MAMP\htdocs\core\ssp.class.php on line 359

it should show no records in table when there are no rows in database table.

Here is the link to ssp.class.php

PLUS:

if i remove GROUP BY id DESC error gone and datatable shows no records in table.

WHAT SHOULD BE CHANGED?NEED SUGGESTIONS.

Answers

  • abdulmanan0331abdulmanan0331 Posts: 5Questions: 1Answers: 0

    I ll really appreciate if someone would help me regarding this issue?

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    The error you are seeing is because $recordsTotal = $resTotalLength[0][0]; is not returning a value. It would be interesting to add var_dump( $resTotalLength ); and see what it is in your use case?

    I rather suspect that the problem is that the SSP script was never designed to handle GROUP BY, so you might need to modify it a little to support that.

    Allan

  • abdulmanan0331abdulmanan0331 Posts: 5Questions: 1Answers: 0

    Thanks allan but as i have talked about it is working when there are rows in my table that it is supporting GROUP BY id desc but when there are no rows in my table i am getting undefined offset 0 error because there are no matched rows of group by id desc i just want to have a message showing no rows in tablerather than the error .so what should be changed in the ssp class? Help would be appreciated thanks

  • abdulmanan0331abdulmanan0331 Posts: 5Questions: 1Answers: 0

    where should i place the var_dump( $resTotalLength ); ?

  • abdulmanan0331abdulmanan0331 Posts: 5Questions: 1Answers: 0
    edited September 2018

    Here is the good news as i was trying to figure out the error ,by placing the following i have solved it somehow(don't know about its consequences or any changes in other column properties but it seems to be solving the undefined offset 0 error around line 351 and 362.
    On line 351 by changing the following:
    $recordsFiltered = $resFilterLength[0][0];
    TO
    if(empty($resFilterLength)){$recordsFiltered="['1','2']";}else{ $recordsFiltered = $resFilterLength[0][0]; }

    On line 359 by changing the following:
    $recordsTotal = $resTotalLength[0][0];
    TO
    if(empty($resTotalLength)){$recordsTotal="['1','2']";}else{ $recordsTotal = $resTotalLength[0][0]; }

    Solves the error.When there were no rows in the table it was giving undefined offset 0 and after changing the above no error and datatable nicely shows : No data available in table :smiley:

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Excellent - great to hear you've got it working.

    Allan

This discussion has been closed.