By following the guide you made for me in the previous ticket I succeded to show rows based on ID numbers, and make the row/table editable from the admin view (admin SQL table)
I have to fetch data from another database reporting system, where all users have an ID number that is connected to a CVR number (Company registration number)
So if the user's ID is 1, then 1 has to be equal to the CVR number (Example: 12121212)
In the table, 'CVR number'' has its own column, as well as the user id.
Why do I need that?
I need this as I working with a client database with more 4000 active customer, that all have 1, or more than 1 location.
All users need access to the booking system after login, so all 4000 clients need a user account.
To avoid creating user account one by one, im going to create user accounts in bulk by CSV file.
By fetching userid to the CVR number, I can easily downloadupload data from one system to another, by recognizing the data by userid, or cvr number.
I hope my question makes sense. Thanks in advance.
Firstly, I would like to sincerely apologize for the delayed response as we have been experiencing an unusually high number of tickets. I am sorry that it has taken longer than usual to respond to your concern and your patience is highly appreciated.
-
I am sorry, but i am not sure if i fully understood all the details from your use-case.
The user ID, from our "Limit users to see only their rows",
this integer number is going to reference the currently logged User ID.
The current user ID is being stored in WordPress table wp_users.
It is auto-increment, so the first user who registers to the WordPress site, will have user ID 1, the next user who registers gets 2, next one 3, and so on...
-
If you already have a unique integer number for each user that you create on the CSV, in that case then you don't need to add an additional user ID column,
but you can use the CVR number as the user ID in our plugin.
- But, the CVR number of the user needs to match the use'rs ID number in the WordPress database "wp_users" table.
-
As i explained on the other ticket,
you can choose any integer column to serve as "userID" - this will just compare to your WordPress users table in the WordPress database ( wp_users table) if the currently logged user has any rows that match the integer column of your chose from the current table.
Or, you can go to the PhPMyAdmin of your database and check in the wp_users table ( wp_ is the default WordPress database table prefix, on your end it can be different)
then search for your user Email and see what's your user ID in wp_users table.
-
If you store all the data on CSV - and each user has rows with CVR number column,
in that case, you can just import the CSV to make a new Manual Table in our plugin - and select the CVR column to serve as the user ID.
You just have to make sure that the users in your WordPress database have the same user ID as the CVR column is - and you will solve the issue.
Can something like that work as a solution for your use-case?
-
Or, if they have a completely separate CVR number - not the same as their WordPress user ID, in that case you can not use the "Limit users to see their own rows" in this way.
-
Then you would have to improvise to filter tables with VAR placeholder in SQL Queries.
You would have to make a page for each user - but if you have 4000 users - i guess that would be too much work.
-
Can you also please elaborate one detail, i did not understand this part?
You wrote :
'So if the user's ID is 1, then 1 has to be equal to the CVR number (Example: 12121212) '
Can you please explain that, i am not understanding how something like that would work,
if user ID has to equal CVR number
( if user ID is 1 , and the CVR number is 12121212, they are different numbers - not equal)
'So if the user's ID is 1, then 1 has to be equal to the CVR number (Example: 12121212) '
Can you please explain that, i am not understanding how something like that would work,
if user ID has to equal CVR number
( if user ID is 1 , and the CVR number is 12121212, they are different numbers - not equal)
----------------------------------------->
So yes, my issue is i working with 3 different database systems, and soon 4, where the client is registrated with data, but all data belongs to a cvr number. (a CVR number in Denmark is companys registration number), but the same client will have different user-id's for 4 systems, but have the same registration number (CVR-number)
So in the previous question i told that we create data everyday for each client from the tire collection, and have to report once a month. It can happen both way, as what we doing here is basicly the same process. --> Entry collection data
But we dont want to do this twice.
We only want to do this one time, and we want to do it from our end - our system.
Each month we can pull out data from our system, and upload a CSV file direct to the goverment collection system.
To do bulk upload to the goverment system we dont have to include a userid, but we will have to include the CVR number, so the system knows which data belongs to who (So yes, the cvr number here is basicly the ID number, but its still not, as the have a user-id, which is not the cvr number)
If we just had pull out data from our end we would not need this solution, but as both have to do import, and export we will need to find a way to combine the users-id to the (cvr-number)
Another example.
We pull out data from another datasytem. The user id will be completly different from the user id we gonna upload to, but the cvr number is the same.
So when we upload data to wpdatatable, then it should regonize the data based on CVR number, as well as the user-id.
In your system you ''allow user only to see their own row''
This functions is based on the user ID.
As you say ''you can choose whatever field you might need as ID''
Thats cool, but..
But by selecting userid from the dropown your system know ''userid'' belongs to an registrated user, which automatic genrated when creating a new user.
I have created a custom field called ''cvr-nr'' thats is required when creating a new user.
Now the user have uniqe ID, but the user also have CVR-number.
So what i want is to use is the cvr-number to ''allow user only to see his own rows''
How do i tell WPdatatable to take the cvr number that are registrated for a user to show only his own rows based on the cvr number?
In that way i can also have 10 different users with uniqe ID, but under the same cvr number, so this will basicly solve my issue with showing info that belongs to other users.
Thank you for this update with clarifications on your goal.
I can see what you mean.
Our feature "users see and edit only own data" is only capable of comparing any integer field with the current user's ID, which is stored in the wp_user table.
Our developers have made it this way, and it will only look for the user ID.
We do not have any way to tell our plugin to use your custom field ''cvr-nr'' user field instead of the user ID field.
In other words, if you wish to use the built-in feature of "Users see and edit only own data" from the Editing Tab,
in this case the placeholder user ID will be used and we currently can't change that.
-
So, at this time we don't have an easy, user-friendly solution for your use-case, I'm afraid.
You can suggest this for our developers, and they will do their best to come up with a solution in the future.
to see if someone may be already suggested this feature. If you can't see it, feel free to add your suggestion there, and as more people vote, the feature will move higher on the priority list.
You can certainly follow our changeLog page if you'd like ( it is also available in the plugin dashboard), where we state any changes/new features/bug fixes during updates;
and our newsletter, so you're informed about new features, bug fixes, freebies, etc.
-
If you wish to try a custom workaround, maybe there could be a way to use custom SQL Queries.
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).
My example SQL Query for the table will be :
SELECT * FROM wp_wpdatatable_44
WHERE company = '%VAR1%'
First, just to initially generate an SQL table with the VAR1 ,
i will set the Cakewalk company name in the VAR1 , in table's Placeholders tab :
-
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 :
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.
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) :
Then for a page where we need only Region 1 filtered, use shortcode [wpdatatable id=1 var1='Region A'] ,
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.
For all of these examples, you could use the "CVR-NR" column as the "pre-filtering column", with the same logic.
Also, please be advised that our support does not provide writing custom SQL Queries for users, we just provide examples and advice to get you started in the right direction.
-
I will ask our 2nd level Team and will report back to confirm if they have any additional advice to try and help you achieve your use-case.
Let me know if this helped in the meantime. Thank you
Firstly, I would like to sincerely apologize for the delayed response as we have been experiencing an unusually high number of tickets. I am sorry that it has taken longer than usual to respond to your concern and your patience is highly appreciated.
-
We got advised by our 2nd level Team.
There is a possible workaround that you can try.
On this example, we made "user roles" as the dependency,
but in your case, you would have to modify this solution and find the "CVR" numbers in your database,
and then link them using the same logic as we show on this example with "user roles".
-
Here it is.
If I have this table:
This is a manual table which has manually entered IDs from wp_users and roles from wp_usermeta:
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:
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:
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.
-
As we said, you would use the same principle, just instead of linking "user roles",
So the table works of course when you simply input the user's id.
WpDatatable have big potential but you limited yourself a lot when this is the only way. It should be really simple to add this function to your plugin.
Anyway, I tried different work around to find a solution for show data based on the cvrnr, and skip the userid settings.
function custom_wpdatatables_filter($sql, $table_id) { global $wpdb; $user_id = get_current_user_id(); $cvrnr = get_user_meta($user_id, 'cvrnr', true); // Assuming you have stored the cvrnr as user meta $sql .= " AND cvrnr = '$cvrnr'"; return $sql; } add_filter('wpdatatables_frontend_table_filter_query', 'custom_wpdatatables_filter', 10, 2);
And modify the shortcode to: [wpdatatable id=7 user_filter='cvrnr']
BUT this doesn't works.
Then I tried to do this in PHP:
global $wpdb; $user_id = get_current_user_id(); $user_cvrnr = get_user_meta($user_id, 'cvrnr', true);
$sql = "SELECT * FROM {$wpdb->prefix}wp_wpdatatable_7 WHERE cvrnr = '{$user_cvrnr}'";
$data = $wpdb->get_results($sql, ARRAY_A);
// Create a new SQL table to store the user's data $table_name = $wpdb->prefix . 'user_' . $user_cvrnr; $wpdb->query("CREATE TABLE IF NOT EXISTS {$table_name} ( wdt_ID INT(11) UNSIGNED AUTO_INCREMENT, userid INT(11), cvrnr VARCHAR(255), pnr VARCHAR(255), firmanavn VARCHAR(255), postnr VARCHAR(255), bynavn VARCHAR(255), indsamlingsdato DATE, indberetningsdato DATE, gruppe1stk INT(11), gruppe1kg DECIMAL(10,2), gruppe2stk INT(11), gruppe2kg DECIMAL(10,2), gruppe3stk INT(11), gruppe3kg DECIMAL(10,2), gruppe4stk INT(11), gruppe4kg DECIMAL(10,2), indberettetaf VARCHAR(255), masterdetail VARCHAR(255), PRIMARY KEY (wdt_ID) )");
to see if someone may be already suggested this feature. If you can't see it, feel free to add your suggestion there, and as more people vote, the feature will move higher on the priority list.
You can certainly follow our changeLog page if you'd like ( it is also available in the plugin dashboard), where we state any changes/new features/bug fixes during updates;
and our newsletter, so you're informed about new features, bug fixes, freebies, etc.
Hi.
By following the guide you made for me in the previous ticket I succeded to show rows based on ID numbers, and make the row/table editable from the admin view (admin SQL table)
I have to fetch data from another database reporting system, where all users have an ID number that is connected to a CVR number (Company registration number)
So if the user's ID is 1, then 1 has to be equal to the CVR number (Example: 12121212)
In the table, 'CVR number'' has its own column, as well as the user id.
Why do I need that?
I need this as I working with a client database with more 4000 active customer, that all have 1, or more than 1 location.
All users need access to the booking system after login, so all 4000 clients need a user account.
To avoid creating user account one by one, im going to create user accounts in bulk by CSV file.
By fetching userid to the CVR number, I can easily downloadupload data from one system to another, by recognizing the data by userid, or cvr number.
I hope my question makes sense.
Thanks in advance.
Hi, kim
Firstly, I would like to sincerely apologize for the delayed response as we have been experiencing an unusually high number of tickets. I am sorry that it has taken longer than usual to respond to your concern and your patience is highly appreciated.
-
I am sorry, but i am not sure if i fully understood all the details from your use-case.
The user ID, from our "Limit users to see only their rows",
this integer number is going to reference the currently logged User ID.
The current user ID is being stored in WordPress table wp_users.
It is auto-increment, so the first user who registers to the WordPress site, will have user ID 1, the next user who registers gets 2, next one 3, and so on...
-
If you already have a unique integer number for each user that you create on the CSV, in that case then you don't need to add an additional user ID column,
but you can use the CVR number as the user ID in our plugin.
- But, the CVR number of the user needs to match the use'rs ID number in the WordPress database "wp_users" table.
-
As i explained on the other ticket,
you can choose any integer column to serve as "userID" - this will just compare to your WordPress users table in the WordPress database ( wp_users table) if the currently logged user has any rows that match the integer column of your chose from the current table.
Or, you can go to the PhPMyAdmin of your database and check in the wp_users table ( wp_ is the default WordPress database table prefix, on your end it can be different)
then search for your user Email and see what's your user ID in wp_users table.
-
If you store all the data on CSV - and each user has rows with CVR number column,
in that case, you can just import the CSV to make a new Manual Table in our plugin - and select the CVR column to serve as the user ID.
You just have to make sure that the users in your WordPress database have the same user ID as the CVR column is - and you will solve the issue.
Can something like that work as a solution for your use-case?
-
Or, if they have a completely separate CVR number - not the same as their WordPress user ID, in that case you can not use the "Limit users to see their own rows" in this way.
-
Then you would have to improvise to filter tables with VAR placeholder in SQL Queries.
You would have to make a page for each user - but if you have 4000 users - i guess that would be too much work.
-
Can you also please elaborate one detail, i did not understand this part?
You wrote :
'So if the user's ID is 1, then 1 has to be equal to the CVR number (Example: 12121212) '
Can you please explain that, i am not understanding how something like that would work,
if user ID has to equal CVR number
( if user ID is 1 , and the CVR number is 12121212, they are different numbers - not equal)
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 | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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
Hi Milos.
Thanks for your reply. Always great!
--------------------------------------------------------Reply---------------------------------------------------------------
'So if the user's ID is 1, then 1 has to be equal to the CVR number (Example: 12121212) '
Can you please explain that, i am not understanding how something like that would work,
if user ID has to equal CVR number
( if user ID is 1 , and the CVR number is 12121212, they are different numbers - not equal)
----------------------------------------->
So yes, my issue is i working with 3 different database systems, and soon 4, where the client is registrated with data, but all data belongs to a cvr number. (a CVR number in Denmark is companys registration number), but the same client will have different user-id's for 4 systems, but have the same registration number (CVR-number)
So in the previous question i told that we create data everyday for each client from the tire collection, and have to report once a month. It can happen both way, as what we doing here is basicly the same process. --> Entry collection data
But we dont want to do this twice.
We only want to do this one time, and we want to do it from our end - our system.
Each month we can pull out data from our system, and upload a CSV file direct to the goverment collection system.
To do bulk upload to the goverment system we dont have to include a userid, but we will have to include the CVR number, so the system knows which data belongs to who (So yes, the cvr number here is basicly the ID number, but its still not, as the have a user-id, which is not the cvr number)
If we just had pull out data from our end we would not need this solution, but as both have to do import, and export we will need to find a way to combine the users-id to the (cvr-number)
Another example.
We pull out data from another datasytem. The user id will be completly different from the user id we gonna upload to, but the cvr number is the same.
So when we upload data to wpdatatable, then it should regonize the data based on CVR number, as well as the user-id.
Does it make sense?? :D
Hi, kim
Thank you for providing examples with more details.
I think I understand it much better now,
i am just not sure if we have an ideal solution for you that is going to filter the data based on the CVR number,
but combined with user ID , as you described.
I will have to check with our senior 2nd level Team.
As soon as they go through everything I will report back to confirm if we have a solution for this use-case,
and I will let you know if any further details/clarifications are required.
Thank you for your patience.
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 | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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
Hi Again..
In your system you ''allow user only to see their own row''
This functions is based on the user ID.
As you say ''you can choose whatever field you might need as ID''
Thats cool, but..
But by selecting userid from the dropown your system know ''userid'' belongs to an registrated user, which automatic genrated when creating a new user.
I have created a custom field called ''cvr-nr'' thats is required when creating a new user.
Now the user have uniqe ID, but the user also have CVR-number.
So what i want is to use is the cvr-number to ''allow user only to see his own rows''
How do i tell WPdatatable to take the cvr number that are registrated for a user to show only his own rows based on the cvr number?
In that way i can also have 10 different users with uniqe ID, but under the same cvr number, so this will basicly solve my issue with showing info that belongs to other users.
Hi, kim
Thank you for this update with clarifications on your goal.
I can see what you mean.
Our feature "users see and edit only own data" is only capable of comparing any integer field with the current user's ID, which is stored in the wp_user table.
Our developers have made it this way, and it will only look for the user ID.
We do not have any way to tell our plugin to use your custom field ''cvr-nr'' user field instead of the user ID field.
In other words, if you wish to use the built-in feature of "Users see and edit only own data" from the Editing Tab,
in this case the placeholder user ID will be used and we currently can't change that.
-
So, at this time we don't have an easy, user-friendly solution for your use-case, I'm afraid.
You can suggest this for our developers, and they will do their best to come up with a solution in the future.
Please feel free to search on our suggestions page,
to see if someone may be already suggested this feature. If you can't see it, feel free to add your suggestion there, and as more people vote, the feature will move higher on the priority list.
You can certainly follow our changeLog page if you'd like ( it is also available in the plugin dashboard), where we state any changes/new features/bug fixes during updates;
and our newsletter, so you're informed about new features, bug fixes, freebies, etc.
-
If you wish to try a custom workaround, maybe there could be a way to use custom SQL Queries.
You can use placeholders for table generation.
1. For example, if you have a MySQL query-based table, you can use this query:
%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).
My example SQL Query for the table will be :
First, just to initially generate an SQL table with the VAR1 ,
i will set the Cakewalk company name in the VAR1 , in table's Placeholders tab :
-
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 :
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.
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) :
Then for a page where we need only Region 1 filtered, use shortcode [wpdatatable id=1 var1='Region A'] ,
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.
I also made a short video example - please check it out here.
-
For all of these examples, you could use the "CVR-NR" column as the "pre-filtering column", with the same logic.
Also, please be advised that our support does not provide writing custom SQL Queries for users, we just provide examples and advice to get you started in the right direction.
-
I will ask our 2nd level Team and will report back to confirm if they have any additional advice to try and help you achieve your use-case.
Let me know if this helped in the meantime. 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 | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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
Hi, kim
Firstly, I would like to sincerely apologize for the delayed response as we have been experiencing an unusually high number of tickets. I am sorry that it has taken longer than usual to respond to your concern and your patience is highly appreciated.
-
We got advised by our 2nd level Team.
There is a possible workaround that you can try.
On this example, we made "user roles" as the dependency,
but in your case, you would have to modify this solution and find the "CVR" numbers in your database,
and then link them using the same logic as we show on this example with "user roles".
-
Here it is.
If I have this table:
This is a manual table which has manually entered IDs from wp_users and roles from wp_usermeta:
So, then I go to create an SQL query based table which will display entries based on user roles using this query:
When I'm logged in with user ID = 1, I see this:
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:
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.
-
As we said, you would use the same principle, just instead of linking "user roles",
you need to link your "CVR" numbers.
We hope this helps.
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 | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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
Hi Again.
So the table works of course when you simply input the user's id.
WpDatatable have big potential but you limited yourself a lot when this is the only way. It should be really simple to add this function to your plugin.
Anyway, I tried different work around to find a solution for show data based on the cvrnr, and skip the userid settings.
function custom_wpdatatables_filter($sql, $table_id) {
global $wpdb;
$user_id = get_current_user_id();
$cvrnr = get_user_meta($user_id, 'cvrnr', true); // Assuming you have stored the cvrnr as user meta
$sql .= " AND cvrnr = '$cvrnr'";
return $sql;
}
add_filter('wpdatatables_frontend_table_filter_query', 'custom_wpdatatables_filter', 10, 2);
And modify the shortcode to: [wpdatatable id=7 user_filter='cvrnr']
BUT this doesn't works.
Then I tried to do this in PHP:
global $wpdb;
$user_id = get_current_user_id();
$user_cvrnr = get_user_meta($user_id, 'cvrnr', true);
$sql = "SELECT * FROM {$wpdb->prefix}wp_wpdatatable_7 WHERE cvrnr = '{$user_cvrnr}'";
$data = $wpdb->get_results($sql, ARRAY_A);
// Create a new SQL table to store the user's data
$table_name = $wpdb->prefix . 'user_' . $user_cvrnr;
$wpdb->query("CREATE TABLE IF NOT EXISTS {$table_name} (
wdt_ID INT(11) UNSIGNED AUTO_INCREMENT,
userid INT(11),
cvrnr VARCHAR(255),
pnr VARCHAR(255),
firmanavn VARCHAR(255),
postnr VARCHAR(255),
bynavn VARCHAR(255),
indsamlingsdato DATE,
indberetningsdato DATE,
gruppe1stk INT(11),
gruppe1kg DECIMAL(10,2),
gruppe2stk INT(11),
gruppe2kg DECIMAL(10,2),
gruppe3stk INT(11),
gruppe3kg DECIMAL(10,2),
gruppe4stk INT(11),
gruppe4kg DECIMAL(10,2),
indberettetaf VARCHAR(255),
masterdetail VARCHAR(255),
PRIMARY KEY (wdt_ID)
)");
// Insert the user's data into the new SQL table
foreach ($data as $row) {
$wpdb->insert($table_name, array(
'userid' => $row['userid'],
'cvrnr' => $row['cvrnr'],
'pnr' => $row['pnr'],
'firmanavn' => $row['firmanavn'],
'postnr' => $row['postnr'],
'bynavn' => $row['bynavn'],
'indsamlingsdato' => $row['indsamlingsdato'],
'indberetningsdato' => $row['indberetningsdato'],
'gruppe1stk' => $row['gruppe1stk'],
'gruppe1kg' => $row['gruppe1kg'],
'gruppe2stk' => $row['gruppe2stk'],
'gruppe2kg' => $row['gruppe2kg'],
'gruppe3stk' => $row['gruppe3stk'],
'gruppe3kg' => $row['gruppe3kg'],
'gruppe4stk' => $row['gruppe4stk'],
'gruppe4kg' => $row['gruppe4kg'],
'indberettetaf' => $row['indberettetaf'],
'masterdetail' => $row['masterdetail']
));
}
Dont work either.
Hello, kim.
I can see that you tried different custom workarounds and are still not able to exactly achieve your use-case.
We are truly sorry, but the use-case you need falls under a custom solution,
you could need a high level of custom SQL Query to achieve something like this.
Please be advised that writing custom SQL Queries or debugging Queries does not fall under what our support covers.
You can check out this official page of WP codex, for help with writing custom Queries.
-
Our senior Team has advised on a possible custom SQL Query that you could create,
and we have shared our working example for using custom User Roles in the reply from January 13, 2023.
On that example, we made "user roles" as the dependency for filtering,
but in your case, you would have to modify this solution and find the "CVR" numbers in your database,
and then link them using the same logic as we show on this example with "user roles".
That is the best advice we can give at this time, and the closest possible example we have to your use-case.
I am sorry that we are not able to provide more assistance for this custom use-case at this time.
You can make a future development suggestion if you wish to see a more user-friendly solution in the future.
Please feel free to search on our suggestions page,
to see if someone may be already suggested this feature. If you can't see it, feel free to add your suggestion there, and as more people vote, the feature will move higher on the priority list.
You can certainly follow our changeLog page if you'd like ( it is also available in the plugin dashboard), where we state any changes/new features/bug fixes during updates;
and our newsletter, so you're informed about new features, bug fixes, freebies, etc.
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 | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia 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