show depending on a where clause

show depending on a where clause

majkellvzmajkellvz Posts: 8Questions: 3Answers: 0

How can I display data depending on a where clause?

This question has an accepted answers - jump to answer

Answers

  • PochoPocho Posts: 3Questions: 1Answers: 1
    Answer ✓

    majkellvz keep in mind I am new with datatables too so this may not be the cleanest way to do it but it worked for me. I used the ssp.class.php helper available here

    https://github.com/DataTables/DataTables/blob/master/examples/server_side/scripts/ssp.class.php

    with server side processing and using the server side script from this example

    https://datatables.net/examples/data_sources/server_side

    Named it getdata.php and configured the DB information then I changed the last few lines to look like this

    require( 'ssp.class.php' );
    
    $where = $_GET['where']."'%\\'".$_GET['statement']."\\'%'";
    
    echo json_encode(
        SSP::complex( $_GET, $sql_details, $table, $primaryKey, $columns, $where )
    );
    
    

    and then the javascript for the table looks like this

    $('#myTable').DataTable( {                                                                    
        ajax: {                                                      
            "url": "getData.php",
            "data": {
                "where": "dbColumnName = 'something' AND dbColumn2 like",
                "statement": "whereValue",
            }
        }
    }
    

    This sent the query to the db as

    SELECT * FROM dbColumns WHERE dbColumnName = 'something' AND dbColumn2 like '%\'whereValue\'%'

    Hope it helps

This discussion has been closed.