where in()

where in()

gledson_eduardogledson_eduardo Posts: 3Questions: 0Answers: 0
edited September 2013 in Editor
Hi,

I used

->where('category', '1') ---------> WHERE category = '1'

and work fine, but I need also like

????? --------------> WHERE category IN ('1', '2','3')

it's possibile??

tks a lot

Replies

  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    Currently, I'm afraid that this is not possible - the `where()` method that Editor exposes doesn't provide the ability to do WHERE IN at this time. I'm looking at making the 1.3 version much more capable, but as I say, not yet.

    This is presumably just for the loading for the data (not the editing)? You could use the `sql()` method ( http://editor.datatables.net/docs/current/php/class-DataTables.Database.html#_sql ) to query the database directly if you want. Just check for `! isset( $_REQUEST['action'] )` to know when DataTables is requesting data.

    Allan
  • gledson_eduardogledson_eduardo Posts: 3Questions: 0Answers: 0
    Hi Allan,

    Tks for you replay,

    Yes, i'm not editing, only loading data.

    I study sql() but I'm not understand


    Gledson
  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    To use `sql()` you just do something like:

    [code]
    $data = $db->sql('SELECT ... FROM ... WHERE ...')->fetchAll();
    [/code]

    Then you have the data from the query and you can `json_encode` it to send to the client.

    Allan
  • gledson_eduardogledson_eduardo Posts: 3Questions: 0Answers: 0
    Next problem:
    When using (SQL) JSON format is not the same as before.

    sql format () is as follows:
    [{"id":"1","0":"1","pst_grad":"0....

    and the original form:
    {"id":-1,"error":"","fieldErrors":[],"data":[],"aaData":[{"DT_RowId":"row_1","id":"1","pst_grad":"0".....

    And not appear in the data grid,

    Tip?
  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    Yes - you need to convert it using PHP. Just loop over the returned array from the SQL query and create an array in the format that you want to return to the client.

    Allan
This discussion has been closed.