Can I add an AND on the select?

Can I add an AND on the select?

Helpdesk LionesaHelpdesk Lionesa Posts: 23Questions: 4Answers: 1

How can I add an AND to the select?

 $carg_hor = $db
        ->select( 'select_gestcol_tab_salarial', ['select_carg_hor_id as value', 'select_carg_hor_id as label'], ['select_categoria_id' => $_REQUEST['values']['gestcol_tab_salarial.select_categoria_id'] ] )
        ->fetchAll();
    echo json_encode( [
        'options' => [
            'gestcol_tab_salarial.select_carg_hor_id' => $carg_hor
        ]
    ] );

I tried something like this

>select( 'select_gestcol_tab_salarial', ['select_carg_hor_id as value', 'select_carg_hor_id as label'], ['select_categoria_id' => $_REQUEST['values']['gestcol_tab_salarial.select_categoria_id'] 
AND $_REQUEST['values']['gestcol_tab_salarial.select_carg_hor_id'] ] )

but it doesn't work

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,990Questions: 87Answers: 421
    edited September 2022

    Since I know SQL I don't like using the Editor "pseudo" code SQL. If you share that view you can use Editor's "raw" method. This allows you to use Editor's db handler. Alternatively you can use your own db handler of course.

    These are examples using Editor's "raw" method with Editor's db handler

    // $editor->db() is the db handler in case $editor 
    // is passed into the function
    $result = $editor->db()->raw()
        ->bind( ':contract_id', $val['contract']['id'] )  
        ->bind( ':who', "G" )
        ->exec( 'SELECT COUNT(*) AS rfaCount 
                   FROM contract_has_rfa   
                  WHERE contract_id = :contract_id 
                    AND who         = :who' );
    $row = $result->fetch(PDO::FETCH_ASSOC);
    if ( ! (bool)$row["rfaCount"] ) {
        $editor->db()->raw()
           ->bind( ':contract_id', $val['contract']['id'] )  
           ->bind( ':approver_id', $_SESSION['id'] )
           ->bind( ':who', "G" )
           ->bind( ':status', "W" )
           ->bind( ':updater_id', $_SESSION['id'] )
           ->bind( ':creator_id', $_SESSION['id'] )                               
           ->exec( 'INSERT  INTO contract_has_rfa
            (contract_id, approver_id, who, status, updater_id, creator_id)  
                            VALUES
            (:contract_id, :approver_id, :who, :status, :updater_id, :creator_id)' );
    }
    
    // $db is the db handler in this case because it is 
    // passed into the function like this
    $stmt = ('SELECT DISTINCT govdept_id 
                FROM govdept_has_user  
               WHERE user_id = :user_id
                 AND role IN ("Principal", "Administrator")');  
    $result = $db ->raw()
                  ->bind(':user_id',$_SESSION['id'])
                  ->exec($stmt);
    $row = $result->fetchAll(PDO::FETCH_ASSOC);
    
  • Helpdesk LionesaHelpdesk Lionesa Posts: 23Questions: 4Answers: 1
    Answer ✓
     $carg_hor = $db
            ->select( 'select_gestcol_tab_salarial', ['select_carg_hor_id as value',  'as label'], ['select_categoria_id' => $_REQUEST['values']['gestcol_tab_salarial.select_categoria_id'], 
    $_REQUEST['values']['gestcol_tab_salarial.select_carg_hor_id'] )
            ->fetchAll();
    
    

    Adding just the "," worked.

    https://editor.datatables.net/docs/current/php/class-DataTables.Database

Sign In or Register to comment.