I am not getting to use placeholders in my PHP code. I have a query which works perfectly without it, but when I try to integrate the placeholder %CURRENT_USER_ID% I am getting errors. I have reviewed the documentation but I didn't find a full example.
Could you please help me with this issue?
The query in PHP:
$cats = $wpdb->get_results("select distinct(category_id) from view_eudp_stats_answers WHERE exam_id in ($exam_ids) and user_id = %CURRENT_USER_ID%");
The error:
[23-May-2018 17:27:17 UTC] Error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%CURRENT_USER_ID%' at line 4 de la base de datos de WordPress para la consulta select distinct(category_id) from view_eudp_stats_answers WHERE exam_id in (15,16) and user_id = %CURRENT_USER_ID% realizada por QM_DB->query
When you have queries like this our suggestion is to make a VIEW in phpmyadmin or any other database management system and see if it will return the right results. if the result is good you can use that query as an input ( SELECT * FROM VIEW_NAME ) and then add a placeholders.
eFor examplo, I have this code in my php file that I am using as datasource. I am returning a seralized array, everything works correct, but I need to put a placeholder for the logged user id; I also need another placeholder ('var1', for example) for the exam ids.
The code is the same I posted the first time, which other information do you need? The use case is the one I have explained, and it is a common use case in your plugin... Please, let me know.
$cats = $wpdb->get_results("select distinct(category_id) from view_eudp_stats_answers WHERE exam_id in ($exam_ids) and user_id = %CURRENT_USER_ID%");
Please, do you have an example about how do I have to implement a placeholder in a custom query in my php file, which I use as datasource.
Hello,
I am not getting to use placeholders in my PHP code. I have a query which works perfectly without it, but when I try to integrate the placeholder %CURRENT_USER_ID% I am getting errors. I have reviewed the documentation but I didn't find a full example.
Could you please help me with this issue?
The query in PHP:
$cats = $wpdb->get_results("select distinct(category_id)
from view_eudp_stats_answers
WHERE exam_id in ($exam_ids) and
user_id = %CURRENT_USER_ID%");
The error:
Thanks in advance.
Regards,
Iban.
HI Iban,
Thank you for your purchase.
When you have queries like this our suggestion is to make a VIEW in phpmyadmin or any other database management system and see if it will return the right results. if the result is good you can use that query as an input ( SELECT * FROM VIEW_NAME ) and then add a placeholders.
Best regards.
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 Bogdan,
I think you are responding to another quetion :) Please, could you check the question of this thread?
Thanks in advance.
Regards,
Iban.
Hi Iban,
Sorry for this, it looks like I pasted something from other ticket.
Do you have any live example of this or on your site so I can take a look and give you my suggestion.
Best regards.
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,
eFor examplo, I have this code in my php file that I am using as datasource. I am returning a seralized array, everything works correct, but I need to put a placeholder for the logged user id; I also need another placeholder ('var1', for example) for the exam ids.
The code is the same I posted the first time, which other information do you need? The use case is the one I have explained, and it is a common use case in your plugin... Please, let me know.
$cats = $wpdb->get_results("select distinct(category_id)
from view_eudp_stats_answers
WHERE exam_id in ($exam_ids) and
user_id = %CURRENT_USER_ID%");
Please, do you have an example about how do I have to implement a placeholder in a custom query in my php file, which I use as datasource.
NOTE: What I am renderizing is a chart.
Thanks in advance.
Regards,
Iban.
Hi Iban,
Sorry for late response we are in the middle of releasing the new product.
As for your case instead of CURRENT USER ID if you want to get the ID you can call this function
$currentUserId = get_current_user_id();
$cats = $wpdb->get_results("
SELECT DISTINCT (category_id)
FROM view_eudp_stats_answers
WHERE exam_id in ($exam_ids) AND
user_id = $currentUserId");
For user_id you can check the WordPress method on this link
But unfortunately using placeholders like VAR1 etc is something that is not possible to achieve with the plugin built in features at the moment.
Best regards.
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