SSP class giving error on mysql syntax when using AS in naming columns array

SSP class giving error on mysql syntax when using AS in naming columns array

brian82brian82 Posts: 7Questions: 3Answers: 0

Naming column using AS

$columns = array(
    array( 'db' => 'a.name',  'dt' => 0, 'field' => 'name' ),
    array( 'db' => 'a.date',  'dt' => 1, 'field' => 'date' ),
    array( 'db' => 'c.name AS other_name',   'dt' => 2, 'field' => 'other_name' ), // this line

Error is happening when using AS to change name of column and it happens on search input and on sorting that column.

this is actual error

An SQL error occurred: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AS other_name LIKE '%test%' 

when AS is removed all works, but then it is problem because you have 2 same columns "name" and same "name" is displayed in both columns in datatable, you can see on image below.

$columns = array(
    array( 'db' => 'a.name',  'dt' => 0, 'field' => 'name' ),
    array( 'db' => 'a.date',  'dt' => 1, 'field' => 'date' ),
    array( 'db' => 'c.name',   'dt' => 2, 'field' => 'name' ),

Answers

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421

    Have you tried

    $columns = array(
        array( 'db' => 'a.name',  'dt' => 0, 'field' => 'name' ),
        array( 'db' => 'a.date',  'dt' => 1, 'field' => 'date' ),
        array( 'db' => 'c.name',  'dt' => 2, 'field' => 'other_name' ),
    

    ?

  • brian82brian82 Posts: 7Questions: 3Answers: 0

    Yes, then i get error Undefined index: other_name

  • brian82brian82 Posts: 7Questions: 3Answers: 0

    Issue fixed you can check here https://github.com/emran/ssp/pull/29

  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin

    Yes, the demo SSP script doesn't cope with aliases. The Editor PHP libraries are far more capable though, and do. They support server-side processing and are free under the MIT license.

    Allan

Sign In or Register to comment.