where condition

where condition

acarlomagnoacarlomagno Posts: 17Questions: 3Answers: 0
edited July 2014 in Editor

hello
I am using this example code in order to fill the combobox list:

if ( ! isset($_POST['action']) ) {
    // Get a list of sites for the `select` list
    $out['companies'] = $db
        ->select( 'companies', 'id as value, vcompany as label' )
        ->fetchAll();
    }

How I insert a 'where' condition ?

antonello

This question has an accepted answers - jump to answer

Answers

  • acarlomagnoacarlomagno Posts: 17Questions: 3Answers: 0

    I tried:

    $db ->select( 'companies', 'id as value, vcompany as label', $where = array($key='companies.id',$value='1'))

    but I received this error:

    Column not found: 1054 Unknown column '0' in 'where clause'

    why ?

  • acarlomagnoacarlomagno Posts: 17Questions: 3Answers: 0

    with this works fine ... is correct to use a raw sql ?

    ->sql('SELECT id as value, vcompany as label FROM companies WHERE id = 1 ' )

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    edited July 2014 Answer ✓

    Yes you can use a raw SQL statement - that's why the sql() function is there :-).

    For the select statement with a condition, you would use something like:

     $db ->select( 'companies', 'id as value, vcompany as label', array( 'id' => '1' ) );
    

    Allan

  • acarlomagnoacarlomagno Posts: 17Questions: 3Answers: 0

    thanks Allan, but where I wrong in normal 'select' function ?

    antonello

  • acarlomagnoacarlomagno Posts: 17Questions: 3Answers: 0

    oops, you had already answered!

This discussion has been closed.