Equivalent Timestamp Query from SQL to PHP Datatable file

Equivalent Timestamp Query from SQL to PHP Datatable file

creativecatcreativecat Posts: 2Questions: 1Answers: 0

I've got some sql code that I run to get a timestamp to equal the curdate()

SELECT tbl_customers.prin, tbl_customers.cust_loaded, tbl_customers.technician...
FROM tbl_customers
WHERE c_status = 1 and DATE(cust_loaded) = curdate()

this runs fine
but I'm trying to get the equivalent in my php file to populate my datatable

Editor::inst( $db, 'tbl_customers', 'id' )
    ->fields(
        Field::inst( 'corder' ),
        Field::inst( 'acct' ),
        Field::inst( 'name' ),
        Field::inst( 'hse' ),
        Field::inst( 'street' ),
        Field::inst( 'city' ),
        Field::inst( 'st' ),
        Field::inst( 'zip' )
    )
    ->where('technician', $_SESSION['svEmpID'])
    ->where('c_status', 1)
    ->where( 'DATE(cust_loaded)' , 'curdate()')
    ->process( $_POST )
    ->json();

I get an error unless I comment out
->where( 'DATE(cust_loaded)' , 'curdate()')

Is this a limitation with datatables or is there something I'm missing.

TIA

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Answer ✓

    The Editor->where() method will always "bind" the second parameter that is passed in, so it wouldn't be executed as a function. However, you can use a closure function there to access the query's where method which does allow the ability to specify a function - see the documentation here - specifically the third example.

    Allan

  • creativecatcreativecat Posts: 2Questions: 1Answers: 0

    Works perfectly thanks Allan!

This discussion has been closed.