Join with more column

Join with more column

netsamnetsam Posts: 2Questions: 0Answers: 0

Hi, I've a table orders and a table client. I want to take either the field cognome or the field address from ort_utenti table (client table)

In join.php I have this:

$data = Editor::inst( $db, 'ort_ordini', 'idOrdine' )
->field(
Field::inst( 'ort_ordini.idOrdine' ),
Field::inst( 'ort_ordini.idCliente' ),
Field::inst ( 'ort_utenti.cognome' )
)
->leftJoin( 'ort_utenti', 'ort_utenti.id', '=', 'ort_ordini.idCliente' )
->process($_POST)
->data();

I'd like to show in a datatable an address field from ort_utenti (users) table

es.
Field::inst ( 'ort_utenti.address' ) ???

What I have to change in join.php and in html page??

Replies

  • netsamnetsam Posts: 2Questions: 0Answers: 0

    I solved the problem.

    I modified the join.php file:

    $data = Editor::inst( $db, 'ort_ordini', 'idOrdine' )
    ->field(
    Field::inst( 'ort_ordini.idOrdine' ),
    Field::inst( 'ort_ordini.idCliente' ),
    Field::inst ( 'ort_utenti.cognome' ),
    Field::inst ( 'ort_utenti.indirizzo' ) // Field from ort_utenti table
    )
    ->leftJoin( 'ort_utenti', 'ort_utenti.id', '=', 'ort_ordini.idCliente' )
    ->process($_POST)
    ->data();

    and modified the script of html page:

            $('#example').dataTable( {
                dom: "Tfrtip",
                ajax: {
                    url: "php-datatables/join.php",
                    type: 'POST'
                },
                columns: [
                    { data: "ort_ordini.idOrdine" },
                    { data: "ort_utenti.cognome" },
                    { data: "ort_utenti.indirizzo" }    // Field from ort_utenti table
                ],
                tableTools: {
                    sRowSelect: "os",
                    aButtons: [
                        { sExtends: "editor_create", editor: editor },
                        { sExtends: "editor_edit",   editor: editor },
                        { sExtends: "editor_remove", editor: editor }
                    ]
                },
                initComplete: function ( settings, json ) {
                    // Populate the site select list with the data available in the
                    // database on load
                    editor.field( 'ort_ordini.idCliente' ).update( json.ort_utenti );
                }
            } );
    
This discussion has been closed.