get the value of two or more cells from a row , option leftjoin

get the value of two or more cells from a row , option leftjoin

trebmaltrebmal Posts: 17Questions: 4Answers: 0
edited June 2015 in Editor

Hola a tothom,
I created a table with option and leftjoin that obtains part of the data from another table. with a one record works properly
The problem is I want that automatically record two or more data, when I select one.

http://debug.datatables.net/evixez

Here my intance

Editor::inst( $db, 'm_comandes1')
    ->fields(

            Field::inst( 'm_comandes1.codi_client'),
        Field::inst( 'clients.codi_navision' ),
        
        
        Field::inst( 'm_comandes1.client' )
            ->options( 'clients', 'nom_client', 'nom_client' ),
        Field::inst( 'clients.nom_client' ),

        Field::inst( 'm_comandes1.activa')
    )
        ->leftJoin( 'clients', 'nom_client', '=', 'm_comandes1.client' )

    ->process( $_POST )
    ->json();

Below, is the result that I get. I need that the value:
"codi_navision": "41001", and the value "nom_client": "RECREATIUS HOLA, S.L." from table clients, loads in "codi_client": null, and "client": "RECREATIUS HOLA, S.L.", form table "m_comandes1".
I can't load the value from "codi_navision": "41001" in "codi_client": null, Show null
The exemples from joins in web, loads the id, but I need the value.

Below a short curt from server interaction from debuguer.

{
        "DT_RowId": "row_13",
        "m_comandes1": {
            "codi_client": null,      
            "client": "RECREATIUS HOLA, S.L.",
            "activa": "1"
        },
        "clients": {
            "codi_navision": "41001",
            "nom_client": "RECREATIUS HOLA, S.L."
        }
    }, {
        "DT_RowId": "row_8",
        "m_comandes1": {
            "codi_client": null,
            "client": "AMUSEMENT, S.A.",
            "activa": "0"
        },
        "clients": {
            "codi_navision": "41002",
            "nom_client": "AMUSEMENT, S.A."
        }

thanks

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi,

    The problem is I want that automatically record two or more data, when I select one.

    I'm afraid I don't quite understand this. Could you possibly clarify what you are looking for?

    Many thanks,
    Allan

  • trebmaltrebmal Posts: 17Questions: 4Answers: 0

    Hola Allan,

    I'm sorry... my poor English mixed with a technical language, is a tremendous mixtoures.

    Well, in relation to the previus post code.
    I followed the examples to join tables, and I created a DataTable with two tables, all right, works well.

    I created the table "comandes1", that obtains part of data from table "clients".
    When I create a register in "comandes1", among other data, I select the name of the client and , save the name , not the id. Up here all right, works well.

    The question:
    I need that at the same time when I select the Name of client, save automaticly the code of client in the table "comandes1" too (client code and client name).

    Thanks

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    My suggestion would be that you should save the client code - not the name. That way, in future if you change the client name (when editing the client table) you only need to update it in one place. This is the idea of referential integrity in a database - one record links to another.

    This way the client code will always give you the name of the client.

    Does that make sense?

    Allan

  • trebmaltrebmal Posts: 17Questions: 4Answers: 0

    Hola Allan,

    Certainly your proposal will be ideal, but actually Is not usual that a client change the name, my be the type of society S.A. to S.L. If a client change all of his name, we consider create a new client.

    My proposal is redundant . But in the future , these tables interact with another tables and my intention was to save as much data as possible in the same table , in order to do more easy futures joins and exports.

    Well, I rethink the project at the same way that the exemples and you propose.

    Thanks Allan

This discussion has been closed.