Okay
  Public Ticket #2131811
Fetching data from multiple tables
Closed

Comments

  • Guillermo started the conversation

    I designed a budget inside the customer portal using wpdatatables, in total we have 15 diferent tables where the end user adds budget, payments done and balance.

    I need to build a summary table that grabs the data from all 15 tables and shows the data.

    Each table is user based therefore only that 1 user will see the data they have inputed and this summary also needs to be this way.

    How can I do this?

  •  2,572
    Aleksandar replied

    Hello Guillermo.

    Thank you for your interest in our plugin.

    If those 15 tables are stored in the database, you could probably use SQL query to pull the necessary information in one table, and use condition like:

    WHERE userid = %CURRENT_USER_ID%

    So the relevant data is displayed only to the customer currently logged in, hiding the data of all other customers.

    Best regards.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • Guillermo replied

    Can you help me do this? I need help from someone that knows the tool and this is very urgent for the client, this is the only thing holding the go live of the website :)

    Pls pls pls pls help me

  • Guillermo replied

    Ive played around building relations with SQL and have had no luck at all...

    the url is :

    https://bodas.cr/presupuesto-nuevo/

    It has budget categories and 15+ tables, what i need to consolidate (add+) is the integer added on each of those tables for "Costo Aproximado" and "Monto Pagado" so that then this can be added into a new table and show a consolidated amount..

    On the new table i need to add a third column with the variance (substract -) between them.

  • Guillermo replied

    made some progress, did ths:

    select userid, sum(montopagado) totalpagado, sum(costoaproximado) totalaproximado
    from
    (
        select userid, montopagado, costoaproximado
        from wpkv_wpdatatable_1_2
        union all
        select userid, montopagado, costoaproximado
        from wpkv_wpdatatable_1_2_1
        union all
        select userid, montopagado, costoaproximado
        from wpkv_wpdatatable_1_2_1_1
        union all
        select userid, montopagado, costoaproximado
        from wpkv_wpdatatable_1_2_1_1_1
        union all
        select userid, montopagado, costoaproximado
        from wpkv_wpdatatable_1_2_1_1_1_1
    ) t
    Group by userid

    its pulling the data but now i need to add "where" the data is only shown for the logged in user at that time and for the data stored that belongs to him only.

    Whats the class name or id used for active user?


  •  2,572
    Aleksandar replied

    Hi Guillermo.

    Good job on doing this.

    You could take advantage of our placeholder here, like mentioned in the previous reply.

    If you have a userid column, then all you need to do is add the WHERE clause, like this:

    select userid, sum(montopagado) totalpagado, sum(costoaproximado) totalaproximado
    from
    (
        select userid, montopagado, costoaproximado
        from wpkv_wpdatatable_1_2
        union all
        select userid, montopagado, costoaproximado
        from wpkv_wpdatatable_1_2_1
        union all
        select userid, montopagado, costoaproximado
        from wpkv_wpdatatable_1_2_1_1
        union all
        select userid, montopagado, costoaproximado
        from wpkv_wpdatatable_1_2_1_1_1
        union all
        select userid, montopagado, costoaproximado
        from wpkv_wpdatatable_1_2_1_1_1_1
    ) t
    Group by userid
    WHERE userid = %CURRENT_USER_ID%
    

    and it will only show the rows associated to the user currently logged in.

    Unfortunately, I am not able to help you in writing custom queries as that is out of scope of the support provided for the plugin, which only refers to advice.

    Best regards.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables