Fill A Select type with an other SQL

Fill A Select type with an other SQL

lifedaniellifedaniel Posts: 68Questions: 4Answers: 0

Hello I would like to know how to fill

editor.field('ctva').update( [
'0%', '6%', '21%'

] );

With an other SQL table. Giving names, and value.
Or can I put PHP code on .js file ??

lifedaniel

Replies

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    You can have PHP output Javascript if you want (I do it on this site). Or you can load the data like in this example: https://editor.datatables.net/examples/simple/join.html

  • lifedaniellifedaniel Posts: 68Questions: 4Answers: 0
    edited August 2014

    I already tried to use this example, but it uses a JOIN. Wich in not my case.

    My php is like this :

    Editor::inst( $db, 'table', 'id_client' )
        ->fields(
            Field::inst( 'id_client' ),         
            Field::inst( 'nom' ),
            Field::inst( 'adresse' ),
            Field::inst( 'cp' )->validator( 'Validate::numeric' ),
            Field::inst( 'ville' ),
            Field::inst( 'pays' ),
            Field::inst( 'tel' ),
            Field::inst( 'fax' ),
            Field::inst( 'gsm' ),
            Field::inst( 'email' )->validator( 'Validate::email' ),
            Field::inst( 'tva' ),
            Field::inst( 'ctva' )   
        )
    ->process( $_POST )
    ->json();
    

    How can I use an other table with this ?

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    The fact that the example uses a join shouldn't really make any difference. Have a look at line 30 in the PHP of the example I linked to:

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

    That's how it gets the data for the example's select list.

    Allan

  • lifedaniellifedaniel Posts: 68Questions: 4Answers: 0

    the first "sites" and second one correspond to what? db name? table? user ?

  • lifedaniellifedaniel Posts: 68Questions: 4Answers: 0
    edited August 2014
        ->process( $_POST )
        
        
        ->json();
        
    if ( ! isset($_POST['action']) ) {
        // Get a list of tva for the `select` list
        $data['datatabletest'] = $db
            ->selectDistinct( 'codes_tva', 'id as value, nom as label' )
            ->fetchAll();
    }
    

    no error and loading but the select is EMPTY..

  • lifedaniellifedaniel Posts: 68Questions: 4Answers: 0

    up to not lose the post

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    the first "sites" and second one correspond to what? db name? table? user ?

    My example above uses the selectDistinct method documented here: http://editor.datatables.net/docs/Editor-1.3.2/php/class-DataTables.Database.html#_selectDistinct . So its arguments are the table and then the field.

    no error and loading but the select is EMPTY..

    Did you use initComplete as shown in the example I linked to before to populate the select based on your datatabletest data?

    Allan

  • lifedaniellifedaniel Posts: 68Questions: 4Answers: 0
    edited August 2014

    Yeah but json.sites correspond to what? Can't find it

    and selectDistinct( $table, $field = "*", $where = null, $orderBy = null )

    doesn't look like ->selectDistinct( 'sites', 'id as value, name as label' )

    dunno how to apply it

  • lifedaniellifedaniel Posts: 68Questions: 4Answers: 0

    I think my problem come from
    initComplete: function ( settings, json ) {
    // Populate the site select list with the data available in the
    // database on load
    editor.field( 'ctva' ).update( json.ctva );
    }

    dunno what to put in update();

  • lifedaniellifedaniel Posts: 68Questions: 4Answers: 0

    OK said nothing everything working now thank you

This discussion has been closed.