server_processing.php

server_processing.php

eduardo12foxeduardo12fox Posts: 17Questions: 0Answers: 0
edited January 2011 in General
Ol

Replies

  • eduardo12foxeduardo12fox Posts: 17Questions: 0Answers: 0
    Hello Allan,

    First I want to say I'm a fan of this script is great and expedited
    a lot of my work. You have done well.

    I'm a beginner in your script and am having a doubt. Forgive me if I already have
    I tried to answer but eDo not found.

    I need to know in detail how I filter my query because I tried to give a
    include only the page that the script returns all rows in their headers I
    was wondering how I move some variables to the
    server_processing2.php

    [code]
    $aColumns = array( 'cod', 'lote', 'produto', 'fornecedor', 'qtd_entrada', 'qtd_atual', 'fracionado', 'preco_custo', 'preco_venda', 'qtd_fracionado_atual',
    'validade' );

    /* Indexed column (used for fast and accurate table cardinality) */
    $sIndexColumn = "produto";

    /* DB table to use */
    $sTable = "relatoriogeral";

    //$sTable = "produto WHERE validade between '2011-12-01' and '2011-12-31'"; -- CASO QUEIRA COM FILTRO --

    /* Database connection information */
    $gaSql['user'] = "root";
    $gaSql['password'] = "";
    $gaSql['db'] = "estoque";
    $gaSql['server'] = "127.0.0.1";

    [/code]


    This is my setup I want to filter this query by the expiration date would therefore like


    select cod, batch, product, supplier, qtd_entrada, qtd_atual, fractionated preco_custo, preco_venda, qtd_fracionado_atual, valid from relatoriogeral WHERE validity Between '2010-01-01 'and '2011-30-01 '


    how I can send to server_processing.php?
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    To send extra information (i.e. the dates to search on) you use a method like that shown in this example: http://datatables.net/examples/server_side/custom_vars.html . Then you need to add an additional part to the WHERE part of the server-side processing script. Possibly something like at line 85:

    [code]
    $sWhere = "WHERE (";
    [/code]

    could become

    [code]
    $sWhere = "WHERE validity Between '2010-01-01 'and '2011-30-01 ' AND (";
    [/code]
    Allan
  • eduardo12foxeduardo12fox Posts: 17Questions: 0Answers: 0
    I did so in index:
    [code]


    $(document).ready( function () {
    var oTable = $('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "server_processing2.php",
    "sDom": 'RCT<"clear">lfrtip',
    "oTableTools": {
    "sSwfPath": "media/swf/copy_cvs_xls_pdf.swf",
    "aoColumnDefs": [
    { "bVisible": false, "aTargets": [ 1 ] }
    ]


    },


    "fnServerData": function ( sSource, aoData, fnCallback ) {
    /* Add some extra data to the sender */
    aoData.push( { "name": "2010-01-01", "value": "2012-12-12" } );
    $.getJSON( sSource, aoData, function (json) {
    /* Do whatever additional processing you want on the callback, then tell DataTables */
    fnCallback(json)
    } );
    }



    } );
    } );


    [/code]

    and no server_processing.php

    Idid so:

    [code]

    $sWhere = "";
    if ( $_GET['sSearch'] != "" )
    {
    $sWhere = "WHERE ( validade between ' ??? ' and ' ??? ' ";
    //$sWhere = "and ("; -- CASO QUEIRA COM FILTRO --
    for ( $i=0 ; $i
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    I think you want:

    [code]
    aoData.push( { "name": "date_end", "value": "2012-12-12" } );
    aoData.push( { "name": "date_start", "value": "2010-01-01" } );
    [/code]
    in your fnServerData. Otherwise you have a variable called 2010-01-01 with the value of 2012-12-12!

    Then you can use $_REQUEST['date_end'] etc in your PHP.

    Allan
This discussion has been closed.