Unable to see result on my WHERE clause on editor

Unable to see result on my WHERE clause on editor

rainolfrainolf Posts: 56Questions: 6Answers: 0

Hi,
as mentioned here http://editor.datatables.net/docs/current/php/source-class-DataTables.Editor.html#356 i'm trying to find a way to make things work.

So lets immagine i have some columns like name, company, owner.

Now i need to modify my WHERE in order to view all records with owner=john.

So if i understand well i should simply modify the function as foolow:
public function where ( $key=owner, $value=john, $op='=' )

Am i correct?

Cause these way doesn't produce any effect...

Thank you

This question has an accepted answers - jump to answer

Answers

  • rainolfrainolf Posts: 56Questions: 6Answers: 0

    Ohh...find it

    just put:

    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'addressbook' )
    ->fields(
    Field::inst( 'name' ),
    Field::inst( 'company' ),
    Field::inst( 'email' ),
    Field::inst( 'owner' ),
    Field::inst( 'public' )
    )
    ->where( $key = "owner", $value = "john", $op = "=" )
    ->process( $_POST )
    ->json();

    My last question would be:

    How to extend this with an additional WHERE clause with OR / AND operator?

    So for example how retrieve records when owner=john OR / AND public=yes ?

    Thank you

  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Hi,

    Good to hear you got your initial question resolved.

    How to extend this with an additional WHERE clause with OR / AND operator?

    Currently the Editor where option only operates on an AND basis. There is no option to use an OR option. It is something I'm going to look at adding in future, particularly now that the join operation have been improved, but for now you would need to query the database directly with your query and output the data as JSON.

    Allan

  • rainolfrainolf Posts: 56Questions: 6Answers: 0

    ok understand.
    And what about inserting a second WHERE clause with and operator?
    How the code shoul be?

    Thank You

  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin

    Just call the where method again:

    $editor
      ->where( 'myColumn1', 'myValue1' )
      ->where( 'myColumn2', 'myValue2' );
    // etc
    

    Allan

This discussion has been closed.