Okay
  Public Ticket #1105156
Show own data
Closed

Comments

  •  6
    Alex started the conversation

    Hello

    How to show to users only own data rows, but not activate online editing tables?

  • [deleted] replied

    Hi Alex,
    Thank you for the purchase.

    Unfortunately something like that is not possible. Users see and edit only their data is possible just when Front-end editing feature is enabled. As a workaround you can enable Front-end editing and enable Users see and edit only their data and then to restrict editing tables just to Administrator users. You'll see Editor roles field where you can select user types that will be allowed to edit wpDataTables on the front-end.

    Hope this helps!

  •  6
    Alex replied

    I did, but then I do not see any records. Talking about gravity forms entries

    Mysql query:

    select le.id, lead_id,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 23 ) sozd,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 21 ) nomer,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 25 ) nomer2,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 2 ) kto,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 1 ) fam,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 5 ) im,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 3 ) ot,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 4 ) naim,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 6 ) ser,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 7 ) nom,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 8 ) kogda,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 9 ) kem,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 10 ) ind,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 17 ) gorod,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 18 ) ul,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 19 ) dom,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 20 ) office,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 11 ) inn,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 12 ) ogrn,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 13 ) summa,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 14 ) datavkl,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 15 ) nomdog,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 16 ) datadog,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 22 ) user

    from wp_rg_lead_detail l, wp_rg_lead le
    WHERE l.form_id = '9'
    AND l.lead_id = le.id
    AND status='active'
    group by lead_id



  • [deleted] replied

    Hi Alex,

    Probably something is wrong with your MySQL query. Can you try to execute in in phpMyAdmin or any other database management software and see does it returns any data and data that you wish to return. If that is not the case you'll have to modify MySQL query by your needs so it would fetch data that you wish.

  •  6
    Alex replied

    This query runs fine in phpMyAdmin and in the table

  • [deleted] replied

    Hi Alex,

    I understand that but do you get the same data when you run it in phpMyAdmin and wpDataTable or you got more data when you execute it in phpMyAdmin?

  •  6
    Alex replied

    Everywhere the same data

  • [deleted] replied

    Hi Alex,

    So you'll have to modify MySQL query to return the data that you wish. If it is returning same data in wpDataTables and in phpMyAdmin then the problem is not up to wpDataTables than with MySQL query. You can test query in phpMyAdmin and when you get the results that you wish and when you are satisfied with the results you can copy that query in wpDataTables and you'll get the same data.

  •  6
    Alex replied

    I did just that. Copied the query into the table. But in edit mode somehow fails to show the record only to its сreator.

  • [deleted] replied

    Hi Alex,

    Creator is defined by User ID column that you set up. Every user on the WordPress have some ID. For example if you are user with ID 1 and you set up some column to be User ID column. You will see only the rows where in that previously defined User ID column value is 1. Did you set it up like that? 

  •  6
    Alex replied

    Yes. I have a column "User login". I do filter it

  • [deleted] replied

    Hi Alex,

    Please provide me a temporary WP-admin login for your site where this happens, so we could log in and take a look ‘from the inside’ as that’s the most efficient way to see and resolve the issue. You can write credentials here just check PRIVATE so nobody can see it.

    Please send me a login of user that should see the data and please send me the ID of that wpDataTable.

  •   Alex replied privately
  • [deleted] replied

    Hi Alex, Sorry for delayed reply.

    In the column user that you set to be User ID column you don't have ID's then some strings like Express, Autograd, Capital etc. and it should be ID's (Integers) of the users. Because of that this feature is not working for you. Please take a look at this tutorial how to set up this feature - Link.

    Also can you try to create MySQL View from your query because it is very complicated, and use this MySQL View to create wpDataTable. If you don't know how to create MySQL View please take a look at this tutorial - Link.


  •  6
    Alex replied

    Hi Milos

    I created new hidden field in Gravity form with merge tag - {created_by:ID}

    Also made a filter by this field - the User ID.

    But ID the user form does not submit correctly, instead of 35 (user Autograd) reports 0. I will think...

  • [deleted] replied

    Hi Alex,

    I didn't quite understand what have you done. Can you explain me in more details. Did you added a new column directly in MySQL query that should be User ID column?

  •  6
    Alex replied

    I created hidden field (#26) in Gravity forms, that saves the ID of the current user

    Next, I added a line in your query -

    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 26 ) userid,

    But this value = 0 in the table

  • [deleted] replied

    Hi Alex,

    Probably something is wrong in the query and value 0 is probably in the database. Did you take a look at the tutorial that I have sent to you. You'll see the whole process of creating User can see and edit only own data table.

    When you create some wpDataTable, in your case MySQL and you want to use User can see and edit only own data feature, you have to check that field and to set User ID column. For example admin user have id 1 and he will see just rows where value is 1 in selected User ID column. Probably your query is wrong and it is returning 0 values.

    When you set table like that and when some user, in this case admin, add new data it will write value 1 in selected User ID column, and based on that value he will later see that row and other users will not be able to see it.

    Hope this is more clear now, please take a look one more time at the tutorial (Video and Text). 

  •  6
    Alex replied

    no, the value 0 makes the form, so at the moment I will deal with it

  •  6
    Alex replied

    Hi Milos

    I have dealt with the request. The user ID must be taken from another table. This query shows the ID of the user true.

    select le.id, lead_id,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 23 ) sozd,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 21 ) nomerAutograd,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 25 ) nomerCapital,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 27 ) nomerTroyka,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 2 ) kto,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 1 ) fam,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 5 ) im,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 3 ) ot,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 4 ) naim,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 6 ) ser,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 7 ) nom,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 8 ) kogda,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 9 ) kem,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 10 ) ind,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 17 ) gorod,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 18 ) ul,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 19 ) dom,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 20 ) office,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 11 ) inn,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 12 ) ogrn,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 13 ) summa,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 14 ) datavkl,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 15 ) nomdog,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 16 ) datadog,
    (select `created_by` from wp_rg_lead le where le.id = l.lead_id) userid,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 22 ) user

    from wp_rg_lead_detail l, wp_rg_lead le
    WHERE l.form_id = '9'
    AND l.lead_id = le.id
    AND status='active'
    group by lead_id

    But since it takes data from two tables. not one, online editing is impossible. But I do not have to. I include it only so that each user could only see their records. But it's not working. Since the user ID is in one table and the remaining data in the other. Or the problem lies elsewhere? See the screenshot
  •  6
    Alex replied

    Hi

    I have corrected the code, but it produces an error:

    select le.id, lead_id,

    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 16 ) datadog,
    (select `created_by` from wp_rg_lead le where le.id = l.lead_id) userid,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 22 ) userid

    from wp_rg_lead_detail l, wp_rg_lead le
    WHERE l.form_id = '9'
    AND l.lead_id = le.id
    AND status='active'
    AND le.created_by = '%CURRENT_USER_ID%'
    group by lead_id


  • [deleted] replied

    Hi Alex,

    Can you explain me what kind of problem do you have in details? When you send me the query it doesn't help me at all, it is better to describe me with what kind of issue you are dealing. Like I already explained you in previous ticket if you want to use User can see and edit only own data you have to have numbers (ID's of users) in column that you set to be User ID column. Did you manage to setup something like that?

  •  6
    Alex replied

    Hi Milos

    I have several online users enter data. When each user loads the table, each should only see their own records. It should not be edited, just read. So I don't want to make an editable table. Incidentally, they have not solved the problem

  • [deleted] replied

    Hi Alex,

    If that is the case, if you want to setup the table without option to edit it, you'll have to create the query like you did already and to add WHERE condition where some column is equal to %CURRENT_USER_ID%. Please do not use GROUP BY in the query because that can create issues in the table. What kind of error do you have where you create a table with %CURRENT_USER_ID% placeholder?

  •  6
    Alex replied

    Error  -The query returned an empty result

    select le.id, lead_id,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 23 ) sozd,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 21 ) nomerAutograd,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 25 ) nomerCapital,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 27 ) nomerTroyka,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 2 ) kto,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 1 ) fam,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 5 ) im,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 3 ) ot,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 4 ) naim,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 6 ) ser,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 7 ) nom,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 8 ) kogda,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 9 ) kem,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 10 ) ind,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 17 ) gorod,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 18 ) ul,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 19 ) dom,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 20 ) office,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 11 ) inn,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 12 ) ogrn,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 13 ) summa,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 14 ) datavkl,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 15 ) nomdog,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 16 ) datadog,
    (select `created_by` from wp_rg_lead le where le.id = l.lead_id) userid,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 22 ) user

    from wp_rg_lead_detail l, wp_rg_lead le
    WHERE l.form_id = '9'
    AND le.created_by = %CURRENT_USER_ID%
    AND l.lead_id = le.id
    AND status='active'
    group by lead_id

    If I remove the grouping, it will be inconvenient table

  • [deleted] replied

    Hi Alex,

    So that probably mean that you don't have the results for that %CURRENT_USER_ID% that you have defined in Placeholders tab. If you put there number 1 it will get you all results where le.created_by column is 1. After you create table like that you have to place it on some page and different users will see different data.

    Can you send me your login credentials of the database and of the WP so I can take a look at this issue? Just check PRIVATE so nobody can see your credentials except us.

  •   Alex replied privately
  • [deleted] replied

    Hi Alex,

    I take a look at your query and something is wrong with it. Please try to execute it in phpMyAdmin just replace %CURRENT_USER_ID% with some number e.g. 35 or 3 because I saw that you have these numbers in that column. After you execute it you'll see what is the error. 

  •  6
    Alex replied

    Hi Milos

    No errors with this code in phpMyAdmin:

    select le.id, lead_id,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 23 ) sozd,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 21 ) nomerAutograd,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 25 ) nomerCapital,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 27 ) nomerTroyka,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 2 ) kto,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 1 ) fam,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 5 ) im,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 3 ) ot,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 4 ) naim,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 6 ) ser,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 7 ) nom,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 8 ) kogda,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 9 ) kem,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 10 ) ind,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 17 ) gorod,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 18 ) ul,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 19 ) dom,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 20 ) office,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 11 ) inn,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 12 ) ogrn,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 13 ) summa,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 14 ) datavkl,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 15 ) nomdog,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 16 ) datadog,
    (select `created_by` from wp_rg_lead le where le.id = l.lead_id) userid,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 22 ) user

    from wp_rg_lead_detail l, wp_rg_lead le
    WHERE l.form_id = '9'
    AND le.created_by = '35'
    AND l.lead_id = le.id
    AND status='active'
    group by lead_id


  • [deleted] replied

    Hi Alex,

    I am aware that this query is working in phpMyAdmin, it is also working in wpDataTables but when you add AND le.created_by = %CURRENT_USER_ID% in where condition it is not working. Can you try to add this in where condition and then try to execute in in phpMyAdmin. Just replace %CURRENT_USER_ID% with some number e.g. 3.

  •  6
    Alex replied

    Hi Milos

    I did not understand you. The following code works there. I suggest you replace %CURRENT_USER_ID%  with number. So already it is

  •  6
    Alex replied

    Hi Milos

    1. Yes

    2. No errors - i see 2 enries with author ID=3

    3. No errors

  • [deleted] replied

    Hi Alex,

    I have created a wpDataTable with ID 6 from your query:

    select le.id, lead_id,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 23 ) sozd,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 21 ) nomerAutograd,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 25 ) nomerCapital,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 27 ) nomerTroyka,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 2 ) kto,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 1 ) fam,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 5 ) im,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 3 ) ot,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 4 ) naim,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 6 ) ser,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 7 ) nom,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 8 ) kogda,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 9 ) kem,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 10 ) ind,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 17 ) gorod,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 18 ) ul,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 19 ) dom,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 20 ) office,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 11 ) inn,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 12 ) ogrn,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 13 ) summa,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 14 ) datavkl,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 15 ) nomdog,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 16 ) datadog,
    (select `created_by` from wp_rg_lead le where le.id = l.lead_id) userid,
    (select value from wp_rg_lead_detail f where f.lead_id = l.lead_id and f.field_number = 22 ) user
    from wp_rg_lead_detail l, wp_rg_lead le
    WHERE l.form_id = '9'
    AND le.created_by = %CURRENT_USER_ID%
    AND l.lead_id = le.id
    AND status='active'
    group by lead_id
    

    And it's working. Can you please check if that is what you want to create?

  •  6
    Alex replied

    Hi Milos

    Yes, the table now shows only the records entered by the user. Thanks

    But when I try to add a check to scrolltable or just save this query gives an error, try it yourself.

  • [deleted] replied

    Hi Alex,

    When you want to save something in the table and you got the message that query doesn't fetch any data that is because you are using %CURRENT_USER_ID% and for your ID there is no data. You'll have to toggle MySQL query Variables and in %CURRENT_USER_ID% input add some number so that query could fetch any data. For my user ID (37) there is no data and table can't be saved, then I replaced 37 with 3 and table is saved because there are at least on result when %CURRENT_USER_ID% column is 3.


  •  6
    Alex replied

    Hi Milos

    Thank you, now it seems clear