database query: modifying $where

database query: modifying $where

jrapa86jrapa86 Posts: 2Questions: 1Answers: 0

Hello, I am working with datatables editor, paid version. I am trying to set up the database so that every query is under the condition that only data corresponding to that particular user is retrieved.

In my personal php script (before implementing datatables) I used :

'' $sql = "SELECT id, username, proc, mrn, supervisor, proc_date, note FROM procedures WHERE username='$username'"; ''

I am looking to add:
WHERE username='$username'";

applies to any data retrieved in the table which can then be edited.

I'm unsure of where to add the modification. Can anyone help guide me in the right direction?

Answers

  • jrapa86jrapa86 Posts: 2Questions: 1Answers: 0

    after further research I found in the instructions I can edit the
    $editor::inst function in 'php libraries', to this:

    $userId = 12;

    $editor->where( function ( $q ) {
    $q->where( 'id', $userId ); // will throw an error!!
    } );

    However, I cannot find the

    $editor->where

    anywhere in any of the code libraries. I used the generator to create my table, I'm not sure if that is complicating me finding it .

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    This manual page should help - it's explaining the where condition. It's contained in the Editor/Options PHP file, so that'll need to be included. You should be able to do something like

    use
        DataTables\Editor,
        DataTables\Editor\Options;
    
    $userId = 12;
    
    $editor->where( function ( $q ) {
    $q->where( 'id', $userId, '=' ); // will throw an error!!
    } );
    

    or

    use
        DataTables\Editor,
        DataTables\Editor\Options;
    
    $userId = 12;
    
    $editor->where( 'id', $userId );
    } );
    

    Colin

This discussion has been closed.