syntax on server side

syntax on server side

classic12classic12 Posts: 228Questions: 60Answers: 4

Hi I have the following working okay

Editor::inst( $db, 'anims' , 'animID')
->fields(
    Field::inst( 'anims.animID' ),
    Field::inst( 'anims.title' ),
    Field::inst( 'anims.url' ),
    Field::inst( 'anims.status' ),
    Field::inst( 'anims.type' ),
    Field::inst( 'anims.thumbnail' )

        )
->where('anims.status', 'active', '=')
->where( 'anims.type', 'iframe', '=' )
//->order('anims.animID','ASC')
->process( $_POST )
->json();

How I do

  1. on there where make the 2 OR
  2. order by anims.animID ASC or DESC

Cheers

Steve Warby

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406
    edited May 2018 Answer ✓

    https://editor.datatables.net/manual/php/conditions

    from the docs:

    Simple OR condition
    To perform a query with an OR condition when using Editor, a grouping is required, as shown below. This is required as Editor will append its own conditions to the queries, as and when it needs to. For example, when reading recently edited data, the primary key value is added as a condition to ensure only that record is read. Grouping your condition ensures that there can be no incorrect interaction between the condition added by Editor and your own.

    order by isn't working with Editor, only for options instances. You are supposed to order data on the client side. If that isn't suitable for you you can use a view with order by. In that case it should be an updatable view though.

    Editor::inst( $db, 'anims' , 'animID')
    ->fields(
        Field::inst( 'anims.animID' ),
        Field::inst( 'anims.title' ),
        Field::inst( 'anims.url' ),
        Field::inst( 'anims.status' ),
        Field::inst( 'anims.type' ),
        Field::inst( 'anims.thumbnail' )
     
            )
    ->where( function ( $q ) {
        $q->where( function ( $r ) {
            $r->where('anims.status', 'active', '=');
            $r->or_where( 'anims.type', 'iframe', '=' );
        } );
    } )
    ->process( $_POST )
    ->json();
    
  • classic12classic12 Posts: 228Questions: 60Answers: 4

    Thanks for the info

This discussion has been closed.