Okay
  Public Ticket #3244829
Combine 2 tables
Closed

Comments

  • Andreas Lippmann started the conversation

    Hello! 

    I created a table to list events (Date/Time, description, which team is needed...) and i have another list with people and there functions.

    Now my idea was to combine this information to a new table and struggle with that. (See attached screenhot)

    My idea was:

    -Create a new table and get the all events from the events list with and also filter the events with a Column so i only get the events where a team is needed.

    -The team people should could choose when they would to join/work on a particular event 

    I hope i could explain my issue and hope you can help me here.

    Thank you

    Andreas

    Attached files:  EXCEL_7W6IeYkkl5.png

  •  1,850
    Miloš replied

    Hi, Andreas.

    Thank you for the description of the use-case along with the screenshot, i think i understood it.

    4076483799.png

    So, if you make two SQL based tables in your database,

    you could make a third SQL based table that is going to pull all this data you need,

    filter on column "Function A needed" to just show rows with "Yes",

    and also add a foreign key column for "Name",  which is going to be used as a 'single value selectbox' so users/members with a specific role could edit and choose names for editing, from a dropdown.

    1. The filtering for "Function A needed" column.

    I will show you some examples how you can predefine filters for tables in our plugin.

    There can be different ways to pre-filter tables in our plugin :

    You can use placeholders for table generation.

    1. For example, if you have a MySQL query-based table, you can use this query:

    SELECT * FROM yourDatabaseTable
    WHERE columnName = '%VAR1%'

    %VAR1% can be defined in the Placeholders tab when you're creating a table, 

    or you can pass VAR1 value in the table's shortcode.

    -

    For example if i have this Master Manual Table,

    and i want to make a dynamic SQL Table with VAR1 placeholder.  ( Then later i can input different VAR1 in the table shortcode on different pages).

    7428149389.png

    My example SQL Query for the table will be :

    SELECT * FROM wp_wpdatatable_44
    WHERE company = '%VAR1%'

    First, to initially generate an SQL table with the VAR1 ,

    i will set the Cakewalk  company name in the VAR1 , in table's Placeholders tab :

    8172791691.png
    5335724844.png

    9566344767.png

    -

    Then, for example, if i want to make a different page for another Company,

     let's say "Adobe".  Then i pass that value in the VAR1 of the table shortcode :

    6925292908.png
    8863319507.png

    2. 

    Or, if you don't add the condition in an SQL query, you can add %VAR1% in column settings -> Filtering, under "Predefined filtering value".

    Then, you can have different versions of the same table, with the VAR1 value passed in the shortcode,

    let's say if we had a "Regions" column and we wish to filter a different region per each page.

    9385158392.png

    If we want page 1 for example only filtered for "Region A" , you can set predefined filter to this column as %VAR1% (filter type has to be set as text) :

    4266306375.png

    Then for a page where we need only Region 1 filtered, use shortcode [wpdatatable id=1 var1='Region A'] ,

    4565461533.png
    6779925578.png

     page 2 for only "Region B", shortcode would be [wpdatatable id=1 var1='Region B'] and so on, 

    to apply the values defined in the shortcode to the filter.

    ( This filtering method can be used for any table type, besides Simple Tables)

    -

    I also made a short video example - please check it out here.

    2. The team people should could choose when they would to join/work on a particular event / only specific members can edit this with dropdown selection :

    This is the more difficult part.  I am not sure if i fully understood.

    6723817064.png

    We don't have an easy built-in feature to achieve filtering per user role,

    but there is a custom workaround that we can suggest.

    You could add custom user roles, through any Membership Plugin, and here is an example of a table.

    If the dependency is a user role, for example, we could make it work.

    If I have this table:

    5458776907.png

    This is a manual table which has manually entered IDs from wp_users and roles from wp_usermeta:

    7855603551.png
    6462766399.png
    7686895681.png

    So, then I go to create an SQL query based table which will display entries based on user roles using this query:

    SELECT  new_table.id AS ID,     
       new_table.role AS Role,    
        new_table.product AS Product,  
          new_table.amount AS Amount
    FROM wp_wpdatatable_6 AS new_table
    JOIN wp_usermeta AS new_table_1
    ON new_table_1.user_id = %CURRENT_USER_ID%
    AND new_table_1.meta_value LIKE CONCAT('%', new_table.role, '%')
    

    When I'm logged in with user ID = 1, I see this:

    9999185249.png

    When I'm logged in with user ID = 4, I see the same thing. And when I'm logged in as one of the subscribers, I can only see the rows where role = subscriber:

    2907856651.png

    The only difference is that as subscriber I don't have access to back-end, so this confirms it is working on both front and back.

    So, we're only left with hiding unnecessary columns, adding names, and so on.




    3. And for making a list of available names for editing from dropdown,

    you can either manually define possible Editing values from the column settings/Data tab/

    4653333223.png

    Or you can make a Foreign Key related column - that pulls only the available values from another table.

    I hope this helps.

    But let me know if i misunderstood that second part, what you need for the members to be able to see and do.


    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    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

  • Andreas Lippmann replied

    Wow. Thank you Milos for this detail answer. Now i will learn how to do that this days and come back when i have more questions.

  •  1,850
    Miloš replied

    Hi, Andreas.smile.png

    You're welcome, i am happy to advise, as much as possible / as much as our Support can cover.

    I know that this is a lot of informations to absorb, but i hope that it helps.

    As i mentioned, perhaps the most difficult part is to configure exactly what you need in regards to "setting groups of members",  and "limiting members with certain custom role to be able to edit".

    I forgot to add this detail, for Editing tables,  we have this "Editing roles",

    this can allow you to set only specific roles to edit specific tables, as well.

    8368349530.png

    So any custom roles you add to your WordPress will appear there, too.

    Something to be aware of.

    Let me know once you try some of these ideas, if you get stuck on any step, and we will do our best to provide assistance as much as we can.

    Thank you.

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    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